Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you stop this script from giving you like a thousand items?

Asked by 10 years ago
local player = script.Parent.Parent
local backpack = player.Backpack

if player.leaderstats then
    while true do
        wait(1)
        if player.leaderstats.Streak.Value == 5 then
            game.ReplicatedStorage.minigun:clone().Parent = backpack
        end
        if player.leaderstats.Streak.Value == 10 then
            game.ReplicatedStorage.AC130:clone().Parent = backpack
        end
    end
end

the script is placed on the starterpack

1 answer

Log in to vote
2
Answered by 10 years ago

You have nothing checking if the player already has the tool, here is what you can use:

local player = script.Parent.Parent
local backpack = player.Backpack

player.CharacterAdded:connect(function() -- Wait for the caracter to load
    if player:FindFirstChild("leaderstats") then -- Check for the leaderstats
        while wait() do -- Create a loop
            if player:FindFirstChild("leaderstats").Streak.Value >= 5 and backpack:FindFirstChild("minigun") == nil then -- Check for the streak and if they don't have the minigun
                game.ReplicatedStorage:FindFirstChild("minigun"):Clone().Parent = backpack -- Give the player the minigun
            end
            if player:FindFirstChild("leaderstats").Streak.Value >= 10 and backpack:FindFirstChild("AC130") == nil then -- Check for the streak and if they don't have the 
                game.ReplicatedStorage:FindFirstChild("AC130"):Clone().Parent = backpack -- Give the player the AC130
            end
        end
    end
end

If this worked please vote up and accept as answer!

~ Aaron

0
The "and not" isn't working. supermarioworld323 45 — 10y
Ad

Answer this question