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

How can you use EquipTools() without causing an error?

Asked by 6 years ago

I am not that good at scripting, especially when tracking down errors . That is why I want to ask you for help

here is a bit of the code:

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        repeat wait() until Character.Humanoid
        local Humanoid = Character:WaitForChild("Humanoid")
        Humanoid.Died:Connect(function()
            Player:LoadCharacter()
            repeat wait() until Character.Humanoid
            wait(2)
            local hum = Character:WaitForChild("Humanoid")
            if Player.TeamColor == BrickColor.new("Bright blue") then           
                Character:WaitForChild("Humanoid"):EquipTool(Player.Backpack:WaitForChild("M4A1-S"))
            elseif Player.TeamColor == BrickColor.new("Bright yellow") then
                Character:WaitForChild("Humanoid"):EquipTool(Player.Backpack:WaitForChild("AK47"))
            end
        end)
    end)
end)

I tried multiple ways of fixing it but I always end with the same results:

UnequipTools can only be called on a Humanoid with a corresponding Player object.

It's been annoying me. I will be glad if you are able to help me out a bit.

0
you could just parent the tool to the charcter.... e.g.. tool.Parent = player.Character abnotaddable 920 — 6y

1 answer

Log in to vote
0
Answered by
mauro21 22
6 years ago

I had the same problem as well for a long time! But for some reason you can't use a variable to equip the tool!

Try this:

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        repeat wait() until Character.Humanoid
        local Humanoid = Character:WaitForChild("Humanoid")
        Humanoid.Died:Connect(function()
            Player:LoadCharacter()
            repeat wait() until Character.Humanoid
            wait(2)
            local hum = Character:WaitForChild("Humanoid")
            if Player.TeamColor == BrickColor.new("Bright blue") then           
 game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):EquipTool(Player.Backpack:WaitForChild("M4A1-S"))

elseif Player.TeamColor == BrickColor.new("Bright yellow") then
                game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):EquipTool(Player.Backpack:WaitForChild("AK47"))
            end
        end)
    end)
end)
Ad

Answer this question