Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i repeat adding 5 expvalue every 10 sec?

----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

1 answer

✓ Accepted answer

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)

1 comment

0

Yeeey thanky you so if i change wait() i change the duration and if i change + then i change the amount of exp given

This discussion is preserved as it was. New answers, comments, and votes are closed.