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.

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

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:

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.
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