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

Can't use onclicked inside a localscript?

Asked by
DevNetx 250 Moderation Voter
8 years ago

So, I've got a localscript for a GUI inside a module script.

Whenever I click the button, the code inside the local script doesn't run UNLESS I have the module script somewhere in the game.

LOCAL SCRIPT:

script.Parent.logo.Button.MouseButton1Click:connect(function()
script.Parent.main.Visible = true
end)

Hierarchy:

  • Players
    • TimeLordSir
      • PlayerGui
        • ScreenGui
          • logo
            • Button
          • main
          • LocalScript
0
After end, add a ) TheHospitalDev 1134 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This appears to be related to replication ordering. What I think is happening is your LocalScript is running before your logo or Button objects are replicated to the player.

This sort of problem can be fixed by using the WaitForChild method:

local main = script.Parent:WaitForChild("main")
script.Parent:WaitForChild("logo"):WaitForChild("Button").MouseButton1Click:connect(function()
main.Visible = true
end)

Without further explaining what module you are talking about or supplying an error message, this is the only problem I can see happen in this situation.

Ad

Answer this question