----script---- game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local experience = Instance.new('IntValue', stats) experience.Name = 'EXP' experience.Value = 0 local level = Instance.new('IntValue', stats) level.Name = 'level' level.Value = 0 experience.Changed:connect(function() level.Value = math.floor(experience.Value / 10) end) end) -----this is a local script----- local player = game.Players.LocalPlayer local leaderstats = player:WaitForChild('leaderstats') local level = leaderstats:WaitForChild('level') local xp = player:WaitForChild('exp') local experience level.Changed:connect(function() if xp.Value < 10 then level.Value = 1 end end end)
how do i repeat 5 exp value every 10 sec so the player will get 5 exp every 10 sec
One method you could use is a while true do loop (which is just an infinite loop). I'm not exactly sure why you would want them to gain 5 exp every 10 seconds but this is one method...
game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local experience = Instance.new('IntValue', stats) experience.Name = 'EXP' experience.Value = 0 local level = Instance.new('IntValue', stats) level.Name = 'level' level.Value = 0 experience.Changed:connect(function() level.Value = math.floor(experience.Value / 10) end) spawn(function() -- So that it runs on a separate thread (making other code executable afterwards) while true do wait(10) -- Executes code after 10 seconds experience.Value = experience.Value + 5 -- Increments the value and loops back to the wait end end) end)
(inside the script)