What I’m trying to do is. 1. Shorten the Player Name & 2 Not require Capitalization for the name while also allowing it. I’m also trying to do this with chat commands so I’m looking to allow any capitalization for both player and the command.
function SplitMessageParts(SplitType,Message,ReturnPart)
if SplitType == "Space" then
local Split = Message:split(" ")
return Split[ReturnPart]
else
--
end
end
game.Players.LocalPlayer.Chatted:Connect(function(Message)
if SplitMessageParts("Space",Message,1) == PortalRequiredText[1].Text and SplitMessageParts("Space",Message,2) == IsAPlayer(SplitMessageParts("Space",Message,2)) then
end
^ My way of finding if the string is valid is also very messy so if I can get any help with that too i’d be amazing.
function IsAPlayer(Name)
for i,v in pairs(game.Players:GetChildren()) do
if v.Name == Name then
return Name
else
end
end
end
function IsAPlayer(Name)
local lowerName = Name:lower()
for _, v in pairs(game.Players:GetPlayers()) do
if v.Name:lower() == lowerName then
return Name
else
for i = 1, #lowerName do
if v.Name:lower():sub(1, i) == lowerName then
return Name
end
end
end
end
end
It will return the correctly capitalized name of the player, if the game finds the player associated with the input name. If you want it to return the player instead, you can simply do: return v
Script
function findPlayer(Name)
local lowerName = Name:lower()
for _, v in pairs(game.Players:GetPlayers()) do
if v.Name:lower() == lowerName then
return v
else
for i = 1, #lowerName do
if v.Name:lower():sub(1, i) == lowerName then
return v
end
end
end
end
end
local searchedPlayer = findPlayer("Player123")
if searchedPlayer then
print("Player was found!")
end
function SplitMessageParts(SplitType, Message, ReturnPart)
if SplitType == "Space" then
local SplitMessage = string.split(Message, " ")
if ReturnPart then
return SplitMessage[ReturnPart]
else
return SplitMessage
end
else
end
end
game.Players.LocalPlayer.Chatted:Connect(function(Message)
if SplitMessageParts("Space", Message, 1) == PortalRequiredText[1].Text and SplitMessageParts("Space", Message, 2) == IsAPlayer(SplitMessageParts("Space", Message, 2)) then
end
end)
function IsAPlayer(Name)
for i, v in ipairs(game.Players:GetChildren()) do
if string.lower(v.Name) == string.lower(Name) then
return v.Name
else
end
end
end
Hopefully I understood what you were trying to do correctly!
My bad… I meant to return the player’s name, not the input name in the function.
function IsAPlayer(Name)
local lowerName = Name:lower()
for _, v in pairs(game.Players:GetPlayers()) do
if v.Name:lower() == lowerName then
return v.Name
else
for i = 1, #lowerName do
if v.Name:lower():sub(1, i) == lowerName then
return v.Name
end
end
end
end
end