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

How would I stop this from executing over and over?

Here is the code:

local valueRequired = 100
game.Players.PlayerAdded:Connect(function(plr)
    local stat = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
    stat.Changed:Connect(function(val)
        if val >= 100 then
            local tool = game.ServerStorage["SapphireCane"]:Clone()
            tool.Parent = plr.Backpack
            plr.CharacterAdded:Connect(function()
                local tool = game.ServerStorage["SapphireCane"]:Clone()
                tool.Parent = plr:WaitForChild("Backpack")
            end)
        end
    end)
end)

How would I stop making this happen so I do not get a bunch of the tool? For I get one tool every time my money changes, and I only want it to happen once.

1 answer

✓ Accepted answer
local valueRequired = 100
game.Players.PlayerAdded:Connect(function(plr)
    local stat = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
	local hasGotten = false
    stat.Changed:Connect(function(val)
        if val >= 100 and hasGotten == false then
			hasGotten = true
            local tool = game.ServerStorage["SapphireCane"]:Clone()
            tool.Parent = plr.Backpack
            plr.CharacterAdded:Connect(function()
                local tool = game.ServerStorage["SapphireCane"]:Clone()
                tool.Parent = plr:WaitForChild("Backpack")
            end)
        end
    end)
end)

1 comment

0

Thanks again!

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