Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i repeat adding 5 expvalue every 10 sec?

Asked by
lyxture 27
8 years ago
----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

Log in to vote
0
Answered by 8 years ago

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)

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 lyxture 27 — 8y
Ad

Answer this question