Hello!
So, I’ve been making a flag system, where a script in ServerScriptService detects if any player said a specific message, then the flag color changes. Everything is generally working fine, however there is 1 value that changes incorrectly after chatting the message “Chequered_Flag”. Instead of the value (inside of a folder located in ReplicatedStorage) changing to “ChequeredFlag”, changes to “RedFlag”
The code is split into 2 scripts, 1st inside of ServerScriptsService, that detects messages and changes them into values and the 2nd one that is located in a part inside workspace.
Code
Script 1 (ServerScriptService)
-- Settings
GreenFlag = "Green_Flag"; -- Message that sets the flag to Green.
YellowFlag = "Yellow_Flag"; -- Message that sets the flag to Yellow.
RedFlag = "Red_Flag"; -- Message that sets the flag to Red.
ChequeredFlag = "Chequered_Flag" -- Message that sets the flag to Chequered.
VirtualSafetyCar = "VSC"; -- Message that sets the flag to VSC.
SafetyCar = "SC"; -- Message that sets the flag to SC.
-- Code
local PlayersService = game:GetService("Players");
local Current = game.ReplicatedStorage.RaceControlStorage.Values.RCS_Current
Current.Value = startFlag
PlayersService.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.find(string.lower(Message), string.lower(GreenFlag)) then
Current.Value = "GreenFlag"
elseif string.find(string.lower(Message), string.lower(YellowFlag)) then
Current.Value = "YellowFlag"
elseif string.find(string.lower(Message), string.lower(RedFlag)) then
Current.Value = "RedFlag"
elseif string.find(string.lower(Message), string.lower(ChequeredFlag)) then
Current.Value = "ChequeredFlag"
elseif string.find(string.lower(Message), string.lower(VirtualSafetyCar)) then
Current.Value = "VSC"
elseif string.find(string.lower(Message), string.lower(SafetyCar)) then
Current.Value = "SC"
end;
end);
end);
Script 2 (Part in workspace):
local Current = game.ReplicatedStorage.RaceControlStorage.Values.RCS_Current
while wait(1/3) do
if Current.Value == "GreenFlag" then
script.Parent.TextureID = ""
script.Parent.BrickColor = BrickColor.new("Lime green")
elseif Current.Value == "YellowFlag" then
script.Parent.TextureID = ""
script.Parent.BrickColor = BrickColor.new("Bright yellow")
elseif Current.Value == "RedFlag" then
script.Parent.TextureID = ""
script.Parent.BrickColor = BrickColor.new("Really red")
elseif Current.Value == "SC" then
script.Parent.TextureID = ""
script.Parent.BrickColor = BrickColor.new("Bright yellow")
elseif Current.Value == "VSC" then
script.Parent.TextureID = ""
script.Parent.BrickColor = BrickColor.new("Bright yellow")
elseif Current.Value == "ChequeredFlag" then
script.Parent.TextureID = "rbxassetid://5413758727"
script.Parent.BrickColor = BrickColor.new("Really black")
end
end
If anything is unclear, please let me know.