Hi, pls help I dont know what to do it says attempt to index nil with wait for child
here is the script:
local Player = game:GetService("Players").LocalPlayer
local Money = Player:WaitForChild("leaderstats"):WaitForChild("Money")
script.Parent.Triggered:Connect(function()
if Money.Value == 15 then
print("Money works")
end
end)
local Player = game:GetService("Players").LocalPlayer
local LeaderstatsFolder = Player:WaitForChild("leaderstats")
local Money = LeaderstatsFolder:WaitForChild("Money")
I’m not sure if this is the solution, but go run it and if it gives an error tell me what the error is and on what line it occured.
script.Parent.Triggered:Connect(function(Player)
local Money = Player:WaitForChild("leaderstats"):WaitForChild("Money")
if Money.Value == 15 then
print("Money works")
end
end)
Try not to use concatenated functions with no check on the return.
local Money = Player:WaitForChild("leaderstats"):WaitForChild("Money")
Split this of into two statements as @RogueBloxxerr suggested.
You can also use a timeout on WaitForCHild() using the second parameter. This gives you an opportunity to accommodate replication times.
local Money = Player:WaitForChild("leaderstats",3); -- this will keep trying to obtain the child for 3 seconds
If this is a server script, the reason it doesn’t work is because there’s no LocalPlayer on the server. You can either:
Put the script into a LocalPlayer in StarterPlayerScripts.
or 2. Change the script to this:
script.Parent.Triggered:Connect(function(player)
local Money = player:WaitForChild("leaderstats"):WaitForChild("Money")
if Money.Value == 15 then
print("Money works")
end
end)