i am making a trick or treat game and i need help with a trick or treat GUI her is the script i made
script.Parent.MouseButton1Click:Connect(function(player) script.Parent.Parent.TextLabel.Text = "Have a Nice Night!" wait(1) game.Players.LocalPlayer.ScreenGui.CandyFrame.Visible = false end)
waht i am really having trouble with is the fourth line it says: 22:27:58.272 - ScreenGui is not a valid member of Player
So basically the GUI's don't load in as fast as the player does. Easy fix.
We use the WaitForChild() Method to wait for a child. WaitForChild() "yields" (waits) the script until it has found a child. Unlike FindFirstChild(), it returns a true or false boolean, making it effective for if statement procedures.
WaitForChild's purpose is to not let parents of the children load too fast making errors.
There is also another problem. You are referencing the GUI under the player itself. There is about two solutions to fix that and I'll show it.
Your script fixed by WaitForChild() and the GUI thing would be:
script.Parent.MouseButton1Click:Connect(function(player) script.Parent.Parent:WaitForChild("TextLabel").Text = "Have a Nice Night!" wait(1) game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").CandyFrame.Visible = false end)
You can ask clarification any time.