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

why is my script giving the player 2 tools instead of 1?

Asked by
lushguy 13
5 years ago
Edited 5 years ago
local Tools = {
["Assassins"] = game.ServerStorage.Tag,}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local NumItems = plr.Backpack:GetChildren()
    plr.Changed:connect(function()
        if #NumItems > 0 then
        return
        end
        if plr.Team == game.Teams.Assassins then
           wait(2) 
           Tools.Assassins:Clone().Parent = plr:WaitForChild("Backpack")
        end
    end)
end)
end)    

1 answer

Log in to vote
0
Answered by 5 years ago

My guess would be that multiple properties are changing when this is happening, giving you multiple tools. Two things we could do to fix and improve this are to first, check that the tool we are putting into the backpack doesn't already exist using logic. We can also only fire the event when the player's team is changed instead of when any property of the player is changed.

local Tools = {
["Assassins"] = game.ServerStorage.Tag,}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local NumItems = plr.Backpack:GetChildren()
    plyr:GetPropertyChangedSignal("Team"):connect(function() -- changed this to the property change signal of team
        if #NumItems > 0 then
        return
        end
        if plr.Team == game.Teams.Assassins and not(plr:WaitForChild("Backpack"):FindFirstChild("Assasins")) then -- check to see if the tool is already in the the backpack
           wait(2) 
           Tools.Assassins:Clone().Parent =                                 plr:WaitForChild("Backpack")
        end
    end)
end)
end)
0
Thanks so much it works perfectly now :) lushguy 13 — 5y
Ad

Answer this question