Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ClickDetector not working correctly? (small script)

Here is the script inside the Click Detector. when you Hover over the brick, it does nothing. There are no errors or anything like that. I've tested it in Play Solo on the Studio and it worked just fine. Is there anything wrong with this?

numb = script.Parent.Number

script.Parent.Parent.ClickDetector.MouseHoverEnter:connect(function(Player)
	stat = Player:FindFirstChild("GUI")
	stat.Value = numb.Value
	print(numb.Value + 5)
end)

script.Parent.Parent.ClickDetector.MouseHoverLeave:connect(function(Player)
	stat = Player:FindFirstChild("GUI")
	stat.Value = 0
	print(numb.Value + 5)
end)

1 answer

Try using this, not sure if it will work or not. It seems to me the error is most likely to be that either the ClickDetector hasn't loaded, the Number value object hasn't loaded or the GUI value object hasn't loaded.

numb = script.Parent.Number

script.Parent.Parent:WaitForChild("ClickDetector").MouseHoverEnter:connect(function(Player)
    stat = Player:FindFirstChild("GUI")
    if not stat then return end
    stat.Value = numb.Value
    print(numb.Value + 5)
end)

script.Parent.Parent:WaitForChild("ClickDetector").MouseHoverLeave:connect(function(Player)
    stat = Player:FindFirstChild("GUI")
    if not stat then return end
    stat.Value = 0
    print(numb.Value + 5)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.