I'm trying to make a GUI that includes multiple small functions(such as a button that lets you open/close another frame and a reset button). I'm using one single LocalScript, whos parent is just ScreenGui, and I have this:
sp=Script.Parent plr=game.Players.LocalPlayer char=plr.Character sp.ResetButton.MouseButton1Click:connect(function() hum=char:findFirstChild("Humanoid") hum.Health=0 end)
For some reason, this works perfectly fine when the localscript is in the button itself, but it doesn't work when it's outside of the button. For convenience sake, I'd rather be able to manage all the buttons in one script. I remember I did something like this last year and it would work, but of course, so much has changed since then, however I don't know if it's something I'm doing wrong or does the code require something extra for it to function again?
The script actually runs before the gui is fully added to the PlayerGui. You can fix that by using WaitForChild
.
sp=script.Parent plr=game.Players.LocalPlayer char=plr.Character sp:WaitForChild("ResetButton").MouseButton1Click:connect(function() hum=char:findFirstChild("Humanoid") hum.Health=0 end)