I dont know how to do this. Should it be on the player?
Basically what I want is a player to be given a certain amount of cash (determined by a stat in leaderstats) every y seconds (also in leaderstats) Its also worth to note that every player may be different. So player a might have to wait 5 seconds for 20 dollars, while player b might have to wait 2 seconds for 40 dollars.
Should It be on the player, or the server? If so, how would I do that? I have no idea where to start with this, so I want to ask people whos a lot smarter than me. I have the amount of time already set, its in the leaderstats (same with the wait time)
Should I make a while loop that just loops through all the players to check their wait time and money per wait. Another problem that may face this script is that there’s gonna be multiple, so should I just loop through all the players and check the wait time and money, or should I have wait time x and wait time y checked on different scripts?
I have never had this problem before so I have no idea. Going to sleep right after this so ill reply in the morning. Cheers
local CashToGive = 100
while task.wait(however_Long) do
for _, plr in pairs(game.Players:GetPlayers()) do
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + CashToGive
end
end
This is not tested. But this should be exactly what you’re looking for.
Everyone here didn’t really seem to read the prompt you gave. You wouldn’t want this to be a client-sided script as it wouldnt properly replicate to the server causing issues later on and leaving it vulnerable to exploiters. Enjoy Man
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new('Folder', plr)
leaderstats.Name = 'leaderstats'
local money = Instance.new('IntValue', plr)
money.Name = 'Money'
-- How much money will be added each time
local incrementAmount = Instance.new('IntValue', plr)
incrementAmount.Name = 'IncrementAmnt'
-- How long it'll wait to give money
local WaitTime = Instance.new('NumberValue', plr)
incrementAmount.Name = 'WaitTime'
-- Main function that gives out $ based on the players values
local function upd()
while true do
task.wait(WaitTime.Value)
plr.leaderstats.Cash.Value += incrementAmount.Value
end
end
-- Threading
local thread = coroutine.wrap(upd)
thread()
end)
All of the provided solutions are server-sided. Also avoid using the parent parameter of the instance class constructor function as it’s inefficient. You’re better off setting the instanced object’s properties first before setting its “Parent” property last.