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

How to remove certain items from backpack if in certain team?

I'm trying to make it so if you're on the team Criminal and you have the items Taser or HandCuffs in your backpack, it gets removed. I tried doing this but it didn't work.

local players = game:GetService("Players")
local criminals = game.Teams.Criminal

players.PlayerAdded:Connect(function(player)
    player.Team = criminals
    player.CharacterAdded:Connect(function(character)
        character.Humanoid.Died:Connect(function()
            if player.Team == criminals then
	           while true do
		 game.Players.LocalPlayer.Backpack.Taser:Destroy()
	           game.Players.LocalPlayer.Backpack.HandCuffs:Destroy()
	end
            end
        end)
    end)
end)

1 answer

It would be better if you added a StringValue on the player to tell which team he is on instead of just getting it from the Team Service, I'm guessing that script is in the StarterGui, so try this:

wait(1)

Player = workspace:FindFirstChild(script.Parent.Parent.Name)

if not Player:FindFirstChild("Team") then
	local value = Instance.new("StringValue")
	value.Name = 'Team'
	value.Parent = Player
end

wait()
if Player.Team.Value ~=  "Criminal" then
	wait()
else
	if script.Parent.Parent.Backpack:FindFirstChild("Taser") and script.Parent.Parent.Backpack:FindFirstChild("HandCuffs") then
		script.Parent.Parent.Backpack.Taser:Destroy()
		script.Parent.Parent.Backpack.HandCuffs:Destroy()
	else
		wait()
	end
end

print 'script done'

--after the script is done, just go to the Player on the Workspace and change the Team value to Criminal, see if it works.

2 comments

0

Didn't make any blue or red underlines in script, I changed my players Team intvalue value to Criminal and I was also on Criminal team, no messages in output but it doesn't work for some reason

0

Odd, It worked fine for me when I tested it, my Taser and Handcuffs got removed as soon as I change the Value to Criminal.. Did you put the lines of code in a Local Script?

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