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

Only add 1 item into backpack?

This script is used to add an item to a players backpack once they are on a certain team but when ever I test it it always adds 4 items instead of only 1.


local Tools = {
    ["Assassins"] = game.ServerStorage.Tag,
}
 while true do
	wait(5)
	game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		plr.Changed:connect(function()
            if plr.Team == game.Teams.Assassins then 
               Tools.Assassins:Clone().Parent = plr:WaitForChild("Backpack")
            end
        end)
    end)
	end)
 end	

4 comments

0

check the backpack for the item before adding it, if its there return nothing

0

What should i put to check i'm stuck on that part

0

it might work fine if you just get rid of the while loop. i dont know why its there.

0

yeah you don't need the while loop

1 answer

Ok so I removed the while loop and I tried to add a check but it still adds 2 items to the players that join the team


local Tools = {
    ["Assassins"] = game.ServerStorage.Tag,
}
	wait(5)
	game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
	local NumItems = plr.Backpack:GetChildren()
		plr.Changed:connect(function()
			if NumItems == 1 then
			return
			end
            if plr.Team == game.Teams.Assassins and #NumItems == 0 then 
               Tools.Assassins:Clone().Parent = plr:WaitForChild("Backpack")
			   print(#NumItems)
            end
        end)
    end)
	end)	




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