How do I check if a models name is any players name?

  1. What do you want to achieve? If a model’s name is any players name in the server, then return/stop

  2. What is the issue? dont know how lol (tables?)

  3. What solutions have you tried so far? trying to use tables and table.find

Not sure on the use case, but I suggest using Players.GetPlayerFromCharacter with the character model as the first argument if the Model you’re checking is the character model.

probably just something like this should work

local model = game.Workspace.Model -- idk what your model is

for i, player in pairs(game.Players:GetPlayers()) do
	if player.Name:lower() == model.Name:lower() then
		-- whatever you want to do
		break
	end
end

I think I found something out, but for some reason the table.find isn’t working.
I have

local players = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
	table.insert(players,player.Name:lower())
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
	table.remove(players,player.Name:lower())
end)

and

and not table.find(players,v.Parent.Name:lower()) then

but it aint working.
The if loop still runs even though both parts print the same name.

I believe you could just do something like

if game:GetService(“Players”):FindFirstChild(Model.Name) then

then you’d do whatever you wanted to do after.

1 Like

Oh so that actually did half-way work, but its the accessories now. The “Handles” are still there, because the parent’s name is the accessory name. How can I check if any baseparts ancestor name is a player name?

edit: oh nevermind I just added a (.parent.name or .parent.parent.name) and it worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.