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

Not detecting the backpack?

Asked by 7 years ago

So i'm making a script for a game of mine and i want part of the script to detect when a players team changes and if the player is on team X then give him team X tools and if there on team Y then give them team Y tools, but i keep getting an error when i try to clone the tools into the players backpack, it keeps saying that Backpack is not a valid member of player. Please help! here is my code:

wait(1)
local Citizen_Color = "Deep orange"

local Citizen_Tools = game.ReplicatedStorage.Citizen_Tools

local Sheriff_Color = "Cork"

local Sheriff_Tools = game.ReplicatedStorage.Sheriff_Tools

game.Players.PlayerAdded:connect(function(Player)
    Player.TeamColor = BrickColor.new("Deep orange")
local Player_TeamColorV = Instance.new("BrickColorValue",game.ReplicatedStorage)
Player_TeamColorV.Name = ''..Player.Name..'_TeamColor'

   Player_TeamColorV.Changed:connect(function()
    print'TeamColor for player was changed'
     if Player_TeamColorV.Value == BrickColor.new(Citizen_Color) then
        for _,Tools in pairs(Citizen_Tools:GetChildren()) do
         local Plr = game.Players:FindFirstChild(Player.Name)
           if Plr then  
             print'Player was found!'
            local Tools_Clone = Tools:Clone()
            Tools_Clone.Parent = Plr.Character
           end  
        end
    end
   end)-
while wait() do
    Player_TeamColorV.Value = Player.TeamColor
end

end)
0
I don't know but, try doing WaitForChild() that may fix it. PolyyDev 214 — 7y

Answer this question