game.Players.PlayerAdded:connect(function()
while true do wait(60)
game.Players.LocalPlayer.leaderstats.Cash.Value = 10 + --gives 10 cash/min
end
end)
it says identifier got end how did i fix?
game.Players.PlayerAdded:connect(function()
while true do wait(60)
game.Players.LocalPlayer.leaderstats.Cash.Value = 10 + --gives 10 cash/min
end
end)
it says identifier got end how did i fix?
game.Players.PlayerAdded:connect(function()
while true do
wait(60)
game.Players.LocalPlayer.leaderstats.Cash.Value = 10 +
end
end)
First of all, I'm guessing you're using a LocalScript so the first thing is PlayerAddedPlayerAdded does not work exactly how it would usually work in ServerScripts, when in a LocalScript and you don't even need it for this kind of script.
while true do
wait(60)
game.Players.LocalPlayer.leaderstats.Cash.Value = 10 +
end
So if we get rid of that function, we have this. There are still a few problems.
while true do
wait(60)
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 10
end
When you are adding to a value, you can't just use 10+ or -10. You need to add onto the value in this case, and so that is why it has to be game.Players.LocalPlayer.leaderstats.Cash.Value + 10
Finally, and this isn't necesarrily important, but to help you out, and make scripting a lot easier, you should do certain things to keep the code clean and structured well.
while wait(60) do
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 10
end
First thing you can see is I just removed the true part in the while loop, and put the wait(60) This is not necessary, but as I said, it just keeps the amount of lines required to as minimal as possible while keeping it clean.
local player = game.Players.LocalPlayer
while wait(60) do
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
end
Another thing I suggest is to use a variable for the LocalPlayer This is to just make the code on line 4 clean and short, and it just looks nicer.
Hope this helped and be sure to +1 and accept answer if this has helped and worked for you. If there is an error, please tell me and I will be sure to fix it ASAP
- NinjoOnline
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
i get this error 4: attempt to index local 'player' (a nil value)
fixed