I am having trouble debugging this script, I want to make it so that every second the Experience changes by 1 and so that every five seconds that the Points change by 1, but the problem is that only the experience changes, not the Points. Here is the code.
game.Players.PlayerAdded:connect(function(plr) local Stats = Instance.new("IntValue",plr) Stats.Name = "leaderstats" Experience = Instance.new("IntValue", Stats) Experience.Name = "EXP" Experience.Value = 0 local Level = Instance.new("IntValue", Stats) Level.Name = "Level" Level.Value = 0 local Points = Instance.new("IntValue", Stats) Points.Name = "Money" Points.Value = 0 while true do Experience.Value = Experience.Value + 1 wait(1) end while true do Points.Value = Points.Value + 1 wait(5) end Experience.Changed:connect(function() Level.Value = math.floor (Experience.Value / 1000) end) end)
When you make a script, the script is given it's own "thread" (not really) to run on. So if you do a wait() in any part of the script, the entire script will be paused until the wait is over. You need to specify to Lua that you want to make it so that something can run on it's own. You can do this two ways:
with spawn() - http://wiki.roblox.com/index.php?title=Global_namespace/Roblox_namespace#spawn
or coroutines - http://wiki.roblox.com/index.php?title=Global_namespace/Coroutine_manipulation
You can find more and see examples on the ROBLOX wiki. Good luck!