Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I find a player if I have his name with lowercase letters?

Asked by 10 years ago

So I'm making a command bar, and for example, I have a kill command. The commands are seen from the textbutton.

My name is Player, and I have this text in the textbutton: kill player

What I want to do: -Check if there is a name "Player" in the game (with the text being 'player', not 'Player') -Kill the player if there is

What I've tried:

local textbox = script.Parent
local textbutton = script.Parent.ExecuteButton

local FindPlayer = function(plr)
    local newplrs = game:GetService('Players'):GetPlayers()
    for _,n in pairs(newplrs) do
        if (string.lower(plr) == string.lower(n)) then
            return true
        end
    end
end

Kill = function(text)
    if (string.sub(text,1,5) == 'kill ') then
        local trgPlayer = FindPlayer(string.sub(text,6))
        if trgPlayer and trgPlayer.Character then
            trgPlayer.Character:BreakJoints()
        end
    end
end

textbutton.MouseButton1Down:connect(function()
    Kill()
end)

Any help would be appreciated.

0
This code looks fine, except for the fact that you never give your Kill function an argument when you call it. Perci1 4988 — 10y
0
The code from 22-24 was just an example I made up in a few seconds, the actual code is way more complicated. Vlatkovski 320 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

With the player's name, use

string.lower()

on it, then when testing if the player is in game.Players use

string.lower()

on the objects in game.Players as well.

0
Does it work? dudemanloserr 15 — 10y
0
Yes, it worked, just can't upvote. Vlatkovski 320 — 10y
0
You should be able to... dudemanloserr 15 — 10y
Ad

Answer this question