I want to achieve a command that allows you to change the team but you’ll get an error when your inside the team you want to change to, i also want the command to work like in javascript with: toLowerCase(), the issues is that is simply doesn’t work, it doesn’t even throw errors, just does nothing at all, i’ve tried several ways of trying to fix this but i can’t find any solution
The script:
local Teams = {
ST = BrickColor.new("Deep orange"),
C = BrickColor.new("Forest green")
}
local NotificationEvent = game.ReplicatedStorage.Events:WaitForChild("NotificationEvent")
local ErrorMessage = "You can't change to that team while your in that team"
local command = "changeteam"
local prefix = "!"
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if msg:sub(1,prefix:len()) == prefix then
if msg:sub(1,command:len()):lower() == command then
if msg:sub(13):lower() == "st" or "sewer" or "sewerteam" then
if Player.TeamColor == Teams.ST then
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.ST then
Player.TeamColor = Teams.ST
end
elseif msg:sub(13):lower() == "c" or "civilian" or "civilianteam" then
if Player.TeamColor == Teams.C then
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.C then
Player.TeamColor = Teams.C
end
end
end
end
end)
end)
Have you tried putting print statements before/after each connection and if statement to work out where it is unexpectedly not progressing. Alternatively have you tried using the debugger to step through and see where it stops?
You’re accounting for the first character in the command which is the prefix, but you’re checking for the command name without the prefix hence why it doesn’t go through. You’d want to start from the 2nd character:
if msg:sub(2, command:len()):lower() == command then
Generally, if your prefix isn’t a single character:
if msg:sub(#prefix+1,command:len()):lower() == command then
local Teams = {
ST = BrickColor.new("Deep orange"),
C = BrickColor.new("Forest green")
}
local NotificationEvent = game.ReplicatedStorage.Events:WaitForChild("NotificationEvent")
local ErrorMessage = "You can't change to that team while your in that team"
local command = "changeteam"
local prefix = "!"
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
warn("1")
if msg:sub(#prefix+1,command:len()):lower() == command then
warn("2")
if msg:sub(13):lower() == "st" or "sewer" or "sewerteam" then
warn("3")
if Player.TeamColor == Teams.ST then
warn("4")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.ST then
warn("4.5")
Player.TeamColor = Teams.ST
end
elseif msg:sub(13):lower() == "c" or "civilian" or "civilianteam" then
warn("5")
if Player.TeamColor == Teams.C then
warn("6")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.C then
warn("6.5")
Player.TeamColor = Teams.C
end
end
end
end)
end)
local Teams = {
ST = BrickColor.new("Deep orange"),
C = BrickColor.new("Forest green")
}
local NotificationEvent = game.ReplicatedStorage.Events:WaitForChild("NotificationEvent")
local ErrorMessage = "You can't change to that team while your in that team"
local command = "changeteam"
local prefix = "!"
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
warn("1")
warn(#msg)
if msg:sub(prefix:len()+1,command:len()+prefix:len()+1):lower() == command then
warn("2")
if msg:sub(13):lower() == "st" or "sewer" or "sewerteam" then
warn("3")
if Player.TeamColor == Teams.ST then
warn("4")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.ST then
warn("4.5")
Player.TeamColor = Teams.ST
end
elseif msg:sub(13):lower() == "c" or "civilian" or "civilianteam" then
warn("5")
if Player.TeamColor == Teams.C then
warn("6")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.C then
warn("6.5")
Player.TeamColor = Teams.C
end
end
end
end)
end)
Yes i do, like i’ve said i’m trying to get this to work like in javascript with .toLowerCase()
That’s why i’m typing into the chat: !ChangeTeam st
But i also tried just typing it in only lowercase
Alright, it seems to work fine for me now, try this code:
local Teams = {
ST = BrickColor.new("Deep orange"),
C = BrickColor.new("Forest green")
}
local NotificationEvent = game.ReplicatedStorage.Events:WaitForChild("NotificationEvent")
local ErrorMessage = "You can't change to that team while your in that team"
local command = "changeteam"
local prefix = "!"
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
warn("1")
if msg:sub(prefix:len()+1,command:len()+prefix:len()):lower() == command then
warn("2")
if msg:sub(13):lower() == "st" or "sewer" or "sewerteam" then
warn("3")
if Player.TeamColor == Teams.ST then
warn("4")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.ST then
warn("4.5")
Player.TeamColor = Teams.ST
end
elseif msg:sub(13):lower() == "c" or "civilian" or "civilianteam" then
warn("5")
if Player.TeamColor == Teams.C then
warn("6")
NotificationEvent:FireClient(Player,ErrorMessage)
elseif not Player.TeamColor == Teams.C then
warn("6.5")
Player.TeamColor = Teams.C
end
end
end
end)
end)