How to find player?

Hi,

I am making admin system.
Problem is my actual name is NewStar_Blox. But if I say /ban newstar_blox it don’t work.
So I want to make it work but this script not working.
I tried this code that I made but it wouldn’t work.

local plrName = "newstar_blox"
local plrId
  for _, v in pairs(game.Players:GetPlayers()) do
    if string.lower(v.Name) == string.lower(plrName) then
      plrId = v.UserId
  end
end

Thank you,

I don’t think your issue is coming from this part of your code.

I made that code to fix this. But it doesn’t work.

Could you post the rest of your code? This bit will work fine as long as it runs after you’ve loaded into the game.

local timeUnits = {d = 24*60*60, h = 60*60, m = 60, s = 1}


local dss = game:GetService("DataStoreService")
local banDS = dss:GetDataStore("CommandPlayerBan")


game.Players.PlayerAdded:Connect(function(plr)
	
	
	local result = nil
	local success, err = pcall(function()
		result = banDS:GetAsync(plr.UserId .. "-BanData")
	end)
	
	if result then
		
		local thenTime = result[1]
		local nowTime = os.time()
		local banTime = result[2]
		local reason = result[3]
		local timeDiff = nowTime - thenTime
		
		if timeDiff < banTime then
			
			local newTime = banTime - timeDiff
			
			plr:Kick(reason .. "\nBanned for " .. newTime .. "s")
			
			
		else
			
			pcall(function()
				banDS:SetAsync(plr.UserId .. "-BanData", nil)
			end)
		end
	end
	
	local Allowed = {
		"Programmer",
		"Tester",
		"3D Designer",
		"Main Developer",
		"Engineer",
		"Artist",
		"Builder",
		"GroupAdmin"
	}
	
	if table.find(Allowed, plr:GetRoleInGroup(6589440))  then
		
		
		plr.Chatted:Connect(function(message)
			
			local splitMsg = string.split(message, " ")
			
			local banCmd = splitMsg[1]
			local plrName = splitMsg[2]
			local banTime = splitMsg[3]
			local reason = "You banned by " .. plr.Name .. " (" .. plr:GetRoleInGroup(6589440) .. ") Reason: " .. splitMsg[4] or "You banned by " .. plr.Name .. " (" .. plr:GetRoleInGroup(6589440) .. ")"
			
			
			if banCmd == "/ban" and plrName and banTime then
				
				local timeUnit = string.sub(banTime, -1, -1)
				local timeAmount = string.sub(banTime, 1, #banTime-1)
				local seconds = timeUnits[timeUnit]
				
				
				if seconds then
					local plrId
					for _, v in pairs(game.Players:GetPlayers()) do
						if string.lower(v.Name) == string.lower(plrName) then
							plrId = v.UserId
						end
					end
					if not table.find(Allowed, game.Players:GetPlayerByUserId(plrId):GetRoleInGroup(6589440)) then
						if plrId then

							local banTimeSeconds = seconds * timeAmount

							pcall(function()
								banDS:SetAsync(plrId .. "-BanData", {os.time(), banTimeSeconds, reason})
							end)

							if game.Players:FindFirstChild(plrName) then

								game.Players[plrName]:Kick(reason .. "\nBanned for " .. banTime)
							end
						end
					end
				end
			end
		end)
	end
end)

Have you done any debugging to find which line its actually failing to get to?

Also this part here:

if game.Players:FindFirstChild(plrName) then
	game.Players[plrName]:Kick(reason .. "\nBanned for " .. banTime)
end

It’s searching for the name then it’s case sensitive. Your earlier part of your code that lowers it doesn’t do anything to help this last line.

1 Like