This is my leaderstats:


local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
 
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = leaderstats

 
end
 
-- Run onPlayerJoin when the PlayerAdded event fires
game.Players.PlayerAdded:Connect(onPlayerJoin)

This is the script I am getting the error on (placed in starter character scripts):

wait(1)
local playerModel = script.Parent
local player = game.Players:GetPlayerFromCharacter(playerModel)

player:WaitForChild("leaderstats")
player.leaderstats:WaitForChild("cash") 
local cash = player.leaderstats.cash

while true do
wait(5)
	cash.Value = cash.Value + 100
end

I get the error in the line where it says 'player.leaderstats:WaitForChild("cash") ' The error says that there is Infinite yield possible on 'Players.pinkcust2vids.leaderstats:WaitForChild("cash")' How can I fix this? Thanks in advance :)!

4 comments

0

Cash is case sensitive, the name is Cash with a capital C, not cash with a lowercase c. Another thing (just a tip) you could do is combine these into one script and just run a while loop to give them their cash when they join.

0

So, change line 6 on the StarterCharacterScripts Script to player.leaderstats:WaitForChild("Cash")

0

Thanks for the help. It works now!

0

No problem!