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

Can't use onclicked inside a localscript?

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

1 comment

0

After end, add a )

1 answer

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.

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