I've been trying to make a script that gives a gun until you have no guns left and refreshes in an hour. It gives the gun, but never stops giving it even though I'm trying to make it so when the Amount = 0 it won't give them anymore. Script:
local Model = script.Parent
local Base = Model.PrimaryPart
local ClickDetector = Base:WaitForChild("ClickDetector")
Amount = 2
local ToolName = "Beretta M9" --the name of the tool the player gets
local WhitelistGroupIds = {
5310854, --ID Goes Here
}
function GiveTool(plr)
if Amount == 2 then
game:GetService("ServerStorage"):FindFirstChild(ToolName)
game:GetService("ServerStorage")[ToolName]:Clone().Parent = plr.Backpack
Amount = 1
elseif Amount == 1 then
game:GetService("ServerStorage"):FindFirstChild(ToolName)
game:GetService("ServerStorage")[ToolName]:Clone().Parent = plr.Backpack
Amount = 0
elseif Amount == 0 then
print ("Out of guns.")
end
end
ClickDetector.MouseClick:connect(function(plr)
if #WhitelistGroupIds > 0 then
for i=1, #WhitelistGroupIds do
if plr:IsInGroup(WhitelistGroupIds[i]) then
GiveTool(plr)
end
end
else
GiveTool(plr)
end
end)
if Amount == 2 then game.Workspace.Houses.ClassifiedTurf.GUIPart.BillboardGui.TextLabel.Text = "Beretta M9 2/2"
end
if Amount == 1 then game.Workspace.Houses.ClassifiedTurf.GUIPart.BillboardGui.TextLabel.Text = "Beretta M9 1/2"
end
if Amount == 0 then game.Workspace.Houses.ClassifiedTurf.GUIPart.BillboardGui.TextLabel.Text = "Beretta M9 0/2"
end
while true do
wait (3600)
Amount = 2
end

1 comment
Why not always check if amount is always > 0?