RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Players.IShafiI.PlayerGui.Script:5: attempt to index nil with 'WaitForChild' - Server - Script:5"
This error is occurring because the script is trying to access a child of the PlayerGui that does not exist or hasn't been replicated yet. The `WaitForChild` function is used to wait for a child of an instance to load. If the child doesn't exist, this function will throw an error. To fix this, you need to ensure that the child you're trying to access (in this case, the StartButton) exists and is replicated to the server before the script tries to access it. Here's how you can do it: ```lua local Players = game:GetService("Players") local function onPlayerAdded(player) local playerGui = player:WaitForChild("PlayerGui") local gui = game.StarterGui.WelcomeGui:Clone() gui.Parent = playerGui gui.Enabled = true local startButton = gui:WaitForChild("StartButton") local function onStartButtonClick() gui.Enabled = false end startButton.MouseButton1Click:Connect(onStartButtonClick) end Players.PlayerAdded:Connect(onPlayerAdded) ``` In this revised script, the `WaitForChild` function is used after the GUI is parented to the PlayerGui. This ensures that the StartButton has been replicated to the server before the script tries to access it.