You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
So I am making a admin and I want it so you only need to type the first words of a player to run the command on him
What is the issue? Include screenshots / videos if possible!
I Don’t know how
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Search And tried to use :find() but it doesn’t detect if the first words are like the pattern it just detects if it found the pattern in a string
I don’t speak English very good so I hope you know what I meant
You could combine string:match alongside string:lower.
An example:
for _,Player in pairs(Players:GetPlayers()) do
if Player.Name:match(Target) then
--code
end
end
--Target here is the person whom the action is being executed on
local Button = script.Parent
local PlayerName = Button.Parent.Player.Text
function Run(TargetPlayer,Speed)
Button.Run_Event:FireServer(TargetPlayer,Speed)
end
Button.MouseButton1Click:Connect(function()
if string.lower(PlayerName) == "me" then
local TargetPlayer = game.Players.LocalPlayer
Run(TargetPlayer,tonumber(Button.Parent.Speed.Text))
elseif string.lower(PlayerName) == "all" then
for _, TargetPlayer in pairs(game.Players:GetChildren()) do
if TargetPlayer:IsA("Player") then
Run(TargetPlayer,tonumber(Button.Parent.Speed.Text))
end
end
elseif string.lower(PlayerName) == "others" then
for _, TargetPlayer in pairs(game.Players:GetChildren()) do
if TargetPlayer:IsA("Player") and TargetPlayer.Name ~= game.Players.LocalPlayer.Name then
Run(TargetPlayer,tonumber(Button.Parent.Speed.Text))
end
end
else
for _,TargetPlayer in pairs(game.Players:GetPlayers()) do
if TargetPlayer.Name:match("^" ..PlayerName) then --Error
Run(TargetPlayer,tonumber(Button.Parent.Speed.Text))
end
end
end
end)
PlayerName = PlayerName:lower()
local targets = { game.Players.LocalPlayer }
if PlayerName == "all" or PlayerName == "others" then
targets = game.Players:GetPlayers()
if PlayerName == "others" then
table.remove(targets, table.find(game.Players.LocalPlayer)
end
else
for _, TargetPlayer in pairs(game.Players:GetPlayers()) do
if TargetPlayer.Name:match("^" ..PlayerName) then
table.insert(targets, TargetPlayer)
end
end
end
for _, target in pairs(targets) do
Run(target,tonumber(Button.Parent.Speed.Text))
end
Edit: This
May also be written as:
else
for _, TargetPlayer in pairs(game.Players:GetPlayers()) do
if TargetPlayer.Name:match("^" ..PlayerName) then
Run(TargetPlayer,tonumber(Button.Parent.Speed.Text))
end
end
return
end
I’ve always cursed Roblox Studio for not having it, but I just didn’t know it existed! Thanks a lot for letting me know! You have just save me hours of debugging!