✓ Accepted answer
There are just multiple small problems within your code but the logic is ok, the main problem is that we do not find the player from the touched part ie when a player touches the brick we get the touched part as an argument that we use to find the player.
Getting a player object can be done by using GetPlayerFromCharacter. This will pass back the player or nil.
Example:-
function OnTouched(hit)
local char = game.Players:GetPlayerFromCharacter(hit.Parent)
print(char)
end
script.Parent.Touched:connect(OnTouched)
As we now can get the player we next need to choose which color to set the image label, we could check the name of the team or the TeamColor which it a BrickColor. Eather method is ok.
Example:-
if player.Team.Name == 'TeamA' then
end
if player.Team.TeamColor == BrickColor.new([constructor]) then
end
Lastly Color3 has a range of 01 but rgb has a range of 0255 if you are using the constructor Color3.new() we need to / 255 to get the range of 0~1 or you can use an alternative constructor Color3.fromRGB() a list of constructors can be found here.
Putting this all together:-
function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr.Team.Name == 'Cytrons' then
script.Parent.BillboardGui.ImageLabel.ImageColor3 = Color3.fromRGB(0,161,255)
else
script.Parent.BillboardGui.ImageLabel.ImageColor3 = Color3.fromRGB(174,0,255)
end
end
end
script.Parent.Touched:connect(OnTouched)
This is a very basic example and this can be improved upon such as using variables and getting the services.
I hope this helps.
1 comment
Does this affect R15 users as while I test it in Studio since the default rig is R15?