I’m trying to make a silly little no effort tycoon game but its not working out how id like it too lol. I’m getting the error “attempt to index nil with WaitForChild” when i do
local leaderstats = Player:WaitForChild("leaderstats")
code:
local Players = game:GetService("Players")
local MoneyGivers = game.Workspace:WaitForChild("MoneyGivers")
local Debounce = false
for i,v in pairs(MoneyGivers:GetChildren()) do
local MoneyToClaim = v:FindFirstChild("MoneyToClaim")
local LabelPart = v:FindFirstChild("LabelPart")
local MoneyGui = LabelPart.MoneyGui
local MoneyLabel = MoneyGui.MoneyLabel
if v:FindFirstChild("GivePart") then
v.GivePart.Touched:Connect(function(Hit)
local Character = Hit.Parent
print("Touched")
if Character then
if not Debounce then
Debounce = true
print("Touch")
local Player = Players:GetPlayerFromCharacter(Character)
local leaderstats = Player:WaitForChild("leaderstats")
local Money = leaderstats.Money
Money.Value = Money.Value + MoneyToClaim.Value
MoneyToClaim.Value = 0
wait(2)
Debounce = false
end
end
end)
end
end
I have tried FindFirstChild, Player.leaderstats, nothings seemed to work. I can collect the money a couple times before i get this error.