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

how to find the nearest name of a player?

Asked by 5 years ago

I was wondering how I would find the name of closest players name? Lets say I want to go ahead and say something like kill void or something. It would run and kill me. So far Ive been using this code which doesnt find the nearest target

   player.Chatted:Connect(function(message) -- trying to make and admin script

    if checkifadmin(player) then

    if string.lower(string.sub(message,1,string.len("kill")))== "kill" then

    print("Working")

    local target = game.Players:FindFirstChild((string.lower(string.sub(message,6))))

    local targetname = target.Name

    local charecter = game.Workspace:WaitForChild(targetname)

    print(charecter)

    charecter.Humanoid.Health = 0

    end

    end

    end)

1 answer

Log in to vote
0
Answered by 5 years ago

What you are looking for is string.find() first argument is the string you are checking, the second one is the string you are using to check the string from arguemnt 1. The rest are optional. It can be found on this link -> https://developer.roblox.com/api-reference/lua-docs/string . The way string.find() works is that it will return the location of where the small section of the string is. For example:

local var1 = string.find("potato","ota") 
print(var1) -- prints "2,4" 
--[[ Because in "2" letters 
that's where it starts and in "4" 
letters, that is where it ends.]]
0
I can explain more because i made admin once SoftlockedUnderZero 668 — 5y
0
Could you explain how I use string.find? voidofdeathfire 148 — 5y
0
She literally just explained it for you. How is this not clear enough? DeceptiveCaster 3761 — 5y
0
No what to input in it i don't understand the output and input of string.find? voidofdeathfire 148 — 5y
0
note string.find will return nil if it does not find anything of the sub string SoftlockedUnderZero 668 — 5y
Ad

Answer this question