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

How do I make a gamepass script in server script storgage?

game.Players.PlayerAdded:Connect(function(player)
local amount = 5 
local timedelay = 2
local currencyname = "Money" 
local Mad = player:FindFirstChild("GP").Mad.Value

while Mad == true do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") and v then
				v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end
end)

I have Mad set to true and Mad is in the leaderstats as a Boolean, but this still doesn't work.

2 comments

0

Ok lets break this down. Once a player joins, if Mads value == true we start a while loop, that will run in pairs for all players? Even if your script did work it makes no sense. Explain what you're trying to do, exactly.

0

im trying to make it so if the player owns the gamepass they get 5 money every 2 seconds

1 answer

This should work. Let me know if you have any issues.

game.Players.PlayerAdded:Connect(function(player)

local amount = 5 
local timedelay = 2
local currencyname = player.leaderstats.Money
local Mad = player:WaitForChild("GP").Mad --use waitforchild so we don't continue before it exists, and don't use .Value in a variable

	if Mad.Value == true then -- if mad is true
		while wait(timedelay) do -- wait (timedelay) seconds then repeat
			currencyname.Value = currencyname.Value + amount -- just simplified with a variable
		end
	end
end)

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