DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
I've been coding at a system that when you put you mouse over a model a billboard GUI would appear and says that models name, and I'm honestly not that great at scripting but I've been at it for a while and this is what I was able to come up with..
Have a local script in the starter GUI that ran a anonymous function on a players mouse.hit(), but mouse = a nil value. How would I access the properties of the mouse, and is there a better way of doing this? |
|
|
If you're trying to get the mouse, try using the 'GetMouse' method of the local player since you are using a local script.
Something like this...
local mouse = game.Players.LocalPlayer:GetMouse()
Wiki page on 'GetMouse'
http://wiki.roblox.com/index.php?title=GetMouse_(Method)/Player |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
Returns mouse as a nil |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
Nvm no it doesn't this is the code I came up with, still needs a lot of thinks but here:
(Localscript in startergui)
local mouse = game.Players.LocalPlayer:GetMouse()
function showdata()
if mouse.Target.Parent.ClassName == "Model" then
print(mouse.Target.Parent.Name)
end
end
-- I don't know how to call this function |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
|
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
local mouse = game.Players.LocalPlayer:GetMouse()
function showdata()
if mouse ~= nil then
if mouse.Target.Parent.className == "Model" then
print(mouse.Target.Parent.Name)
end
end
end
mouse.Move:connect(showdata) |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
Next, the billboard gui would have to go in the players playergui for it to be local..
Just set the billboardgui.Adornee to the mouse.Target for it to display over the mouse's target
Set the billboard gui's text to be the mouse.Target.Parent.Name for the name to display |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
Thank you so much, Anything I can do to repay? |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
It's fine, you came to a place where help is free.
Btw, i made a mistake!
if mouse ~= nil then
Change this line to
if mouse.Target ~= nil then
This is so it doesn't error when u hover over the sky. |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
local mouse = game.Players.LocalPlayer:GetMouse()
function showdata()
if mouse.Target ~= nil then
if mouse.Target.Parent.className == "Model" then
print("datamodel working")
script.Datagui:Clone()
end
end
end
mouse.Move:connect(showdata)
How would I clone a GUI into playergui, so when I hover over something it pops up with a gui at the mouse? |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
Oh, at the mouse? so you don't want billboard gui's.
In that case;
local mouse = game.Players.LocalPlayer:GetMouse()
function showdata()
if mouse.Target ~= nil then
if mouse.Target.Parent.className == "Model" then
print("datamodel working")
data = script.Datagui:Clone()
data.Parent = game.Players.LocalPlayer.PlayerGui
end
end
end
mouse.Move:connect(showdata) |
|
DrFeynmanJoin Date: 2013-08-07 Post Count: 178 |
And to keep the cloning at a minimum? This is what I'm trying to replicate (sorry)
http://www.roblox.com/Fading-Embers-place?id=102210997 |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
local mouse = game.Players.LocalPlayer:GetMouse()
function showdata()
if mouse.Target ~= nil then
if mouse.Target.Parent.className == "Model" then
print("datamodel working")
if game.Players.LocalPlayer.PlayerGui:findFirstChild("Datagui") == nil then
data = script.Datagui:Clone()
data.Parent = game.Players.LocalPlayer.PlayerGui
end
end
end
end
mouse.Move:connect(showdata) |
|
|
So you want some form of tooltip that appears whenever you hover over an object. If you are trying to replicate the Gui in Fading embers, it won't be that easy since there are probably more than one script keeping track of things. Things such as the name of the object and some characteristics. If you are just trying to replicate the tooltip that comes up, it shouldn't be too hard. You just check which model the part belongs to with this function...
function GetParentModel(instance)
if instance.Parent ~= workspace then
GetParentModel(instance)
elseif instance.ClassName == "Model" then
return instance
end
end
Although it checks for the highest parent so it might be inappropriate. Rename the model to what you want to show up on the tooltip and just create a TextLabel beside the mouse with the model's name. |
|