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

Can yall help me with this Candy Giver Script i got so far?

Asked by 4 years ago

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

0
I just realised its the 30th i have been working on this since the 10th this month Vortex_Vasne 89 — 4y
0
You know what? im going to keep working on this and release the update next halloween Vortex_Vasne 89 — 4y
0
AND i got the houses done like 4 days ago Vortex_Vasne 89 — 4y
0
all GUI elements are descendants of player.playerGui, and not the player itself theking48989987 2147 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question