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

I don't understand why this simple local script doesn't work with a screen gui?

Asked by 3 years ago
game.StarterGui.ScreenGui.MouseButton.MouseButton1Click:Connect(function()
    print("working")
end)

this is a local script under a textbutton under a screen gui, but whenever i run it is ends up no printing anything, plz help!

2 answers

Log in to vote
1
Answered by
gskw 1046 Moderation Voter
3 years ago

The issue is that the contents of StarterGui are copied to the PlayerGui, and PlayerGui is what you see. You can't click a button inside StarterGui, it's just there waiting to be copied over. What you want instead is:

script.Parent.MouseButton1Click:Connect(function()
    print("working")
end)

The LocalScript will only run once it has been copied to PlayerGui, and from there it will obtain the button correctly, using script.Parent. Note that you could also do this:

local button = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").MouseButton

button.MouseButton1Click:Connect(function()
    -- ...
end)
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

StarterGui just replicates everything to the LocalPlayer.PlayerGui So you should change everything in the PlayerGui and not StarterGui. Put your script under the ScreenGui and not under your TextButton.

script.Parent.MouseButton.MouseButton1Click:Connect(function()
    print("Working")
end)

Answer this question