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

How do i change the color of a brick depending on the team?

Asked by 5 years ago

What i mean is if you touch a brick if your team is "Red" it will change to Red or if it was blue it would change to blue.

3 answers

Log in to vote
0
Answered by 5 years ago
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --make sure what has been touched is an actual character by checking if it has a humanoid
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- here we get the player object of the character
        assert(plr ~= nil,"what has been touched is not a player's character") -- this breaks the function and errors ("what has been touched is not a player's character") if the condition is false which means that it errors if the character that has been touched is **not** a player's character

        local teamColor = plr.Team.TeamColor --here we directly get the player's Team and then its BrickColor (which is named TeamColor, just for teams only though)
        script.Parent.BrickColor =  teamColor -- and then change the script's parent BrickColor to it.
    end
end)
0
Thanks man works great n SamZeKat 28 — 5y
0
So glad I helped :D GGRBXLuaGG 417 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

99% sure this is a troll dude anyway

if team == "Red" then
script.Parent.Color = "Red"
end
0
no its not i already see some error ;/ SamZeKat 28 — 5y
0
Fister, u suck. Psudar 882 — 5y
0
lol i bet u forgot to put the script in the brick xDDD ISkyLordDoge 37 — 5y
Log in to vote
0
Answered by 5 years ago

try this, its off the top of my head so if it doesn't work don't witch hunt me lol (this would also be in a normal script btw)

local teams = game:GetService("Teams")

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and teams == "Red" then --insert the name of your team
        script.Parent.Color = "Red" --insert the color of the team
end)

i know this most likely didn't work but that's the gist of what your final product will be. Research it more and try to tweak it. Make sure to mark as answered if I helped :D

0
This wouldnt work. You're comparing a service to a string called "Red" Also you can't use a string for Color, it needs a Color3 value or something.. Psudar 882 — 5y
0
again, was at the top of my head XD BigChildren 77 — 5y

Answer this question