I have made an exp system with some simple scripting but i want to make something like a multiplier. Thus the longer the players in-game the more exp(leaderstats) the player gets. so 30 minutes x1.2, 1 hour x1.5, and so on. I’ve already tried but my mind got fried in the progress i ended up undoing the mulitplier and asking here on devforum. Any Solutions?
I don’t understand your specific value you’re trying to increase by. But I’ll try
Something like this?
local expMultiplier = {}
--each player in seconds
local time = {}
while task.wait() do
for q,w in game:GetService("Players"):GetPlayers() do
--multiplier is every 30 minutes, increases by 0.2?
expMultiplier[w] = 0.2*(time[w]/1800)
end
end
You could just simply make a wrapper function which adds exp to players and multiplies it by their multiplier value which increases every X amount of time and adds them Y amount of multiplier (assuming of course that you have the “boilerplate” leaderstats)
Someting like this:
local Players = game:GetService("Players")
local MULTIPLIER_INCREMENT = 1
local MULTIPLIER_TIME = 1
function GiveEXP(player : Player, amount : number)
local leaderstatsFolder = player:WaitForChild("leaderstats")
local expEntry = leaderstatsFolder:WaitForChild("EXP")
local multiplierEntry = leaderstatsFolder:WaitForChild("Multiplier")
local multiplier = mutliplierEntry.Value
-- You don't want to reset their exp probably
if multiplier == 0 then multiplier = 1 end
expEntry += amount * multiplier
end
coroutine.wrap(function()
while task.wait(MULTIPLIER_TIME) do
for _, player in ipairs(Players:GetPlayers()) do
local leaderstatsFolder = player:WaitForChild("leaderstats")
local multiplierEntry = leaderstatsFolder:WaitForChild("Multiplier")
multiplierEntry.Value += MULTIPLIER_INCREMENT
end
end
end)()