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

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

Asked by 7 years ago

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.

01local players = game:GetService("Players")
02local criminals = game.Teams.Criminal
03 
04players.PlayerAdded:Connect(function(player)
05    player.Team = criminals
06    player.CharacterAdded:Connect(function(character)
07        character.Humanoid.Died:Connect(function()
08            if player.Team == criminals then
09               while true do
10         game.Players.LocalPlayer.Backpack.Taser:Destroy()
11               game.Players.LocalPlayer.Backpack.HandCuffs:Destroy()
12    end
13            end
14        end)
15    end)
16end)

1 answer

Log in to vote
0
Answered by 7 years ago

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:

01wait(1)
02 
03Player = workspace:FindFirstChild(script.Parent.Parent.Name)
04 
05if not Player:FindFirstChild("Team") then
06    local value = Instance.new("StringValue")
07    value.Name = 'Team'
08    value.Parent = Player
09end
10 
11wait()
12if Player.Team.Value ~=  "Criminal" then
13    wait()
14else
15    if script.Parent.Parent.Backpack:FindFirstChild("Taser") and script.Parent.Parent.Backpack:FindFirstChild("HandCuffs") then
View all 25 lines...
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 barrettr500 53 — 7y
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? KatAnimz 18 — 7y
Ad

Answer this question