I'm trying to make it to were every 10 seconds you get 5 credits. works in studio but not in game... Everything works fine but the adding cash at the bottom of the script. Any idea on how to make it work?
function CreateStats(NewPlayer) local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Value = 0 local Credits = Instance.new("IntValue") Credits.Name = "Credits" Credits.Value = 50 Credits.Parent = leaderstats leaderstats.Parent = NewPlayer return leaderstats end game.Players.ChildAdded:connect(CreateStats) while true do wait(10) game.Players.LocalPlayer.leaderstats.Credits.Value = game.Players.LocalPlayer.leaderstats.Credits.Value + 5 end
IncreaseStats = coroutine.create(function(player) while true do wait(10) player.leaderstats.Credits.Value = player.leaderstats.Credits.Value + 5 end end) function CreateStats(NewPlayer) local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Value = 0 local Credits = Instance.new("IntValue") Credits.Name = "Credits" Credits.Value = 50 Credits.Parent = leaderstats leaderstats.Parent = NewPlayer coroutine.resume(IncreaseStats [NewPlayer]) return leaderstats end game.Players.PlayerAdded:connect(CreateStats)
The LocalPlayer variable is a variable that can only be used inside of a LocalScript, which is inside of a Player. I've also changed the Event to .PlayerAdded as it is only being called when a Player was added. And the last, but not least problem is the while true do -loop, which disables the script to do anything else than what's inside this loop. I've put it into a coroutine, which is something like a seperate script, that works paralell to the rest of the script.