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)
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.]]