Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

ClickDetector not working correctly? (small script)

Asked by
lomo0987 250 Moderation Voter
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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)

Ad

Answer this question