Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script no work?

Happy Near Years Eve everyone. Anyway, so this value (with the script in it) is placed into your character from a different script (That works). The script that is not working is supposed to change the value of the StringValue to something specific, which depends on which team you are on. However, the script doesn't work. I have no idea why, and Output gave me nothing. Can someone please help me? Here's the script:

local check = game.Players:getPlayerFromCharacter(script.Parent.Parent)

repeat 
wait()
until check:findFirstChild("TeamColor")

while true do

if check.TeamColor == ("Bright violet") then
wait(0.1)
script.Parent.Value = "AL"
elseif check.TeamColor == ("Bright yellow") then
wait(0.1)
script.Parent.Value = "Brazil"	
elseif check.TeamColor == ("Bright blue") then
wait(0.1)
script.Parent.Value = "China"
elseif check.TeamColor == ("White") then
wait(0.1)
script.Parent.Value = "EU"	
elseif check.TeamColor == ("Bright orange") then
wait(0.1)
script.Parent.Value = "India"	
elseif check.TeamColor == ("Brown") then
wait(0.1)
script.Parent.Value = "NorthKorea"	
elseif check.TeamColor == ("Bright red") then
wait(0.1)
script.Parent.Value = "Russia"	
elseif check.TeamColor == ("Bright green") then
wait(0.1)
script.Parent.Value = "US"	
end 
end 

1 answer

This is an easily fixable but common mistake.

You're trying to compare a Color3value with a String value.

You cannot do:

if check.TeamColor == ("Bright violet") then

Instead, it has to be:

if check.TeamColor == BrickColor.new("Bright violet") then

3 comments

0

It still won't work, except Output actually gave me something this time. Output gave me this: "Players.Player.PlayerGui.Insert.Allegiance.Checker:5: attempt to index local 'check' (a nil value)"

0

It could possibly be that you said "check = game.Players:getPlayerFromCharacter" when the 'g' in "getPlayerFromCharacter" should be capitalized...so like this: check = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

0

If that doesn't work, give me some more information - Is this in a local script? Whose player from character are you trying to get?

This discussion is preserved as it was. New answers, comments, and votes are closed.