Hi, I’m wanting to change a color for a beam, based off a player’s team. I have triple checked my code, googled but I’m still having trouble.
In the script I have printed the player’s team color as well as if the if statement is being run(which is not) OUTPUT:
Bright blue (printed) / Bright red (printed)
Skipped If Statement (printed)
script.Parent.Fire.OnServerEvent:Connect(function(player)
local color = player.TeamColor
print(color)
if color == "Bright red" then
print("Entering If Statement")
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(159, 0, 13)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(159, 0, 13))
})
elseif color == "Bright blue" then
print("Entering If Statement")
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(9, 0, 158)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(9, 0, 158))
})
else
print("Skipped If Statement")
end
end)
-- Note this isn't the full script
I might of forgot to put more info you need more please ask thanks.
Player.TeamColor has the value type of a BrickColor, not a String. That means to check if a color is a specific BrickColor in an if statement, you’ll have to construct a BrickColor through BrickColor.new().
So instead of if color == "Bright red", it will be if color == BrickColor.new("Bright red"), and so on.
I used the same thing to change a part in my script and it worked
local TCP = script.Parent:WaitForChild("TeamColorparts")
if color == "Bright red" then
color = BrickColor.new(21)
elseif color == "Bright blue" then
color = BrickColor.new(23)
end
I don’t think It would make sense to use BrickColor.new BrickColor.new
Constructs the closest BrickColor that can be matched to the specified RGB components.
local color = player.TeamColor
local TCP = script.Parent:WaitForChild("TeamColorparts")
if color == "Bright red" then
color = BrickColor.new(21)
elseif color == "Bright blue" then
color = BrickColor.new(23)
end
Yes, but once its in a variable doesn’t it make it a string/int?
script.Parent.Fire.OnServerEvent:Connect(function(player)
local color = player.TeamColor.Name
print(color)
if color == "Bright red" then
print("Entering If Statement")
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(159, 0, 13)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(159, 0, 13))
})
elseif color == "Bright blue" then
print("Entering If Statement")
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(9, 0, 158)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(9, 0, 158))
})
else
print("Skipped If Statement")
end
end)
No, storing something in a variable doesn’t automatically make it string/int. If you store a BrickColor value in a variable, it will remain a BrickColor - and you can check it using BrickColor.new() as I’ve told you in my previous reply.
The reason that the above reply worked (the one marked as the solution), is that in it you’re using player.TeamColor.Name which converts the BrickColor into a string, and then you check it as a string. It’s just an alternative.
You can also convert the BrickColor to its Number value or its Color value, using player.TeamColor.Number and player.TeamColor.Color respectively.