I want this to prevent from spawning tools in my game so I made a list of all of the tools that are in my game and tried making a script so that if the player has a tool that does not match the list that I have then it will get removed, issue here is that it is removing all of the tools, even the ones in the game.
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
while true do wait()
wait(0.5)
for i, v in pairs(player.Backpack:GetChildren()) do
if v.Name ~= "2DGame" or v.Name ~= "SelfieStick" or v.Name ~= "Suitcase" or v.Name ~= "Coffee" or v.Name ~= "FirstAid" or v.Name ~= "HoverBoard" or v.Name ~= "SegwayHoverboard" or v.Name ~= "SoccerBall" or v.Name ~= "SuperFlyGoldBoombox" or v.Name ~= "Sword" then
v:Destroy()
end
end
end
end)
end)
Note that I had more but I removed it to make it simpler for you guys. How can I fix this?

4 comments
That is a very good script and it works, I am thankful for your help. I am trying to wrap my head around how it works however and that is puzzling me.
Please tell me if my interpretation is correct. As character loads, a while true do loads and then it starts iterating whatever is in player.Backpack and then it iterates whatever is in the tools table. If something in the Backpack has the same name as something in the tools table, it will set exist=true and then break out of the "for i, t in pairs(tools) do" and then move back to the first loop w
I got cut off but its fine. What happens...oh I got it now. If something does not match, it never runs through that "if v.name == t then", or it does but it simply just goes to the two ends and then that "if exist ==false" will run because exist was set to false previously.
Apologize for taking so long. And you're pretty spot on. The 'for' loop and arrays/tables are a pretty powerful thing when it comes to coding in ,well,anything. Roblox has a lot of useful functions and i'm pretty sure if you go to the wikia they'll provide a snippet of code to help you out,