Error with attempt to index nil with 'WaitForChild'

— Fixed thank you guys for checking this —

This is nil on the server. The player parameter is available instead which is always there and automatic.

Quest.OnServerEvent:Connect(function(player)
	wait(1)
	player:WaitForChild(“leaderstats”).Coins.Value = player:WaitForChild(“leaderstats”).Coins.Value + 4
end)
1 Like

I tried but… still the same errors.

local Player = game.Players.LocalPlayer
local Rep = game:GetService("ReplicatedStorage")
local Quest = Rep.QuestRemotes:WaitForChild("Quest1")

Quest.OnServerEvent:Connect(function()
	wait(1)
	
	Player:WaitForChild("leaderstats").Coins.Value = Player:WaitForChild("leaderstats").Coins.Value + 4
	
end)

error :

ServerScriptService.Script:8: attempt to index nil with 'WaitForChild'

Forgot the Player in the function () brackets (this means player parameter within the function)

local Rep = game:GetService("ReplicatedStorage")
local Quest = Rep.QuestRemotes:WaitForChild("Quest1")

--Put player here
Quest.OnServerEvent:Connect(function(Player )--put player here
	wait(1)
	
	Player:WaitForChild("leaderstats").Coins.Value += 4
	
end)
1 Like