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

How to Get a Tool Equipped Based on Team?

Asked by 9 years ago

Hello, I have the following script.

function giveWeapon(part)
    if part:GetChildren("Humanoid") then
        if part.TeamColor == "Really blue" then
            local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
            BlueLaserGun.Parent = game.StarterPack
        end
        if part.TeamColor == "Really red" then
            local RedLaserGun = game.Workspace.RedLaserGun:Clone()
            RedLaserGun.Parent = game.StarterPack
        end
    end
end
script.Parent.Touched:connect(giveWeapon)

Now, this is inserted in a part and whenever I touch it, even though there are established teams, I get the error saying that TeamColor isn't a valid member of part. The Blue and Red LaserGuns do exist in Workspace. Can someone tell me why this isn't working? I would really appreciate it.

0
It's cause inside that part their is no 'TeamColor' hold on a sec NinjoOnline 1146 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

So your problem was that a part does not have a teamcolor, so let's fix that.

function giveWeapon(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then
        if player.TeamColor == BrickColor.new("Really blue") then
                local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
                    BlueLaserGun.Parent = game.StarterPack
            elseif player.TeamColor == BrickColor.new("Really red") then
                    local RedLaserGun = game.Workspace.RedLaserGun:Clone()
                    RedLaserGun.Parent = game.StarterPack
        end
    end
end

script.Parent.Touched:connect(giveWeapon)

So what I did was got the 'Player', which Player is the object that has the TeamColor, while you were looking for TeamColor inside the 'Character'. Hope this helped.

If this doesn't work, then reply back or edit your question with the error and I'll go back and see what I missed.

EDIT I editted line 4 and 7 to include BrickColor.new(), as the colors are a brickcolor. Script should work now.

  • NinjoOnline
0
Team Colors are BrickColor values, might want to show that on line 4 and 7 M39a9am3R 3210 — 9y
0
Hi... it still isn't working, but I'm going to try inserting .BrickColor in various places, see where it works... but I'm going to keep trying, and that's it, I guess. yoman1776 85 — 9y
0
Oh yeah, I spotted the problem, as M39a9am3R said, lines 4 and 7 have been editted so it will work now NinjoOnline 1146 — 9y
0
Hmm... still not working, but it is being cloned into the StarterPack. I just can't see it in my toolbar when I play. Also, I added a print for testing purposes, and it is detecting which team I am on, but it isn't letting me use the tools which are in starterpack. yoman1776 85 — 9y
View all comments (2 more)
0
I have actually just found out what it is... I was putting the tool in starterpack, not backpack. Duh. *slams head on table* Well, thanks for all the help! yoman1776 85 — 9y
0
Oh yeah :P I should have spotted that XD NinjoOnline 1146 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago
function giveWeapon(part)
    if part.Parent.Humanoid then
        if part.TeamColor == BrickColor.new("Really blue") then
            local BlueLaserGun = game.Workspace.BlueLaserGun:Clone()
            BlueLaserGun.Parent = game.StarterPack
        end
        if part.TeamColor == BrickColor.new("Really red") then
            local RedLaserGun = game.Workspace.RedLaserGun:Clone()
            RedLaserGun.Parent = game.StarterPack
        end
    end
end
script.Parent.Touched:connect(giveWeapon)

0
thumbs down... for what connorxvi 15 — 9y

Answer this question