In the game that I'm making I require that when the mouse hovers over something, it checks if it has a certain child and then runs a script. Heres what I tried that didn't work:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() --Getting the player's mouse mouse.Move:connect(function() --When the mouse moves local target = mouse.Target if target:FindFirstChild(game.Workspace.Build.Object.Value) then --do this end end)
EDIT: So this is a localscript that'll get the player's mouse movements. If the target of the mouse has a child named the same as a StringValue in 'Object' -- Child of Build.
LocalScript
local player = game.Players.LocalPlayer local mouse = player:GetMouse() --Getting the player's mouse mouse.Move:connect(function() -- connect the function local target = mouse.Target -- Get the mouse target if target then -- if the mouse is targeting something, if not, no need to run the script local check = target:FindFirstChild(game.Workspace.Build.Object.Value) -- Make sure the Value is a String/Object Value if check then -- Now we see if the target has a child named of that value print("Test") -- Do whatever here end end end)
You should get a basic understanding of how to do this!
Hope this helps!
You want to check if the target of your mouse has a certain child, so why are you checking through game.workspace? I don't know what child you want it to look after but if we say it's Object
for example then:
if target:FindFirstChild("Object") then
There is no reason to check through the whole workspace because then you're not even checking after the targets children which will not work with FindFirstChild
. And Value
is not a child of anything, it's a property.