The script gives players 5 Skulls(Cash) every minute. But I wanted to add a max limit on how many skulls the players can have at one time. when I tried, I realised that 'while true do' is a loop, and I'm not sure how to add the limit onto it, without breaking the script.

local function checkCash(player)

local skulls = Instance.new("StringValue")
skulls.Name = 'Skull Tokens'
skulls.Parent = player
	
local storage = Instance.new("Folder")
storage.Name = player.Name.."'s Storage"
storage.Parent = replicatedstorage
		
local ServerSkulls = Instance.new("IntValue")
ServerSkulls.Name = player.Name.."'s Skull Tokens"
ServerSkulls.Parent = storage	
while true do
	if ServerSkulls.Value >= 0 then	
			wait(60)
			ServerSkulls.Value = ServerSkulls.Value+5
			skulls.Value = ServerSkulls.Value
	else
		if ServerSkulls.Value >= 1000000000000 then
			print(player.Name.." has Max Skulls")
			end
		end
	end
end

4 comments

0

change line 17 to: ServerSkulls.Value = math.min(ServerSkulls.Value+5,1000000000000)

0

That should prevent it from exceeding the max value

0

Thank you, I'll try that

0

Alright that worked, Thanks again :D