How to check if a member of a table is inside the player's character

What I am trying to do / the issue:
I’m trying to see if a player is “wearing” a helmet. When the player presses a UI button, any members of a table that exist inside of the player’s character will be destroyed. I’ve tried different ways around it, but I have no idea on how to get this to work.

game.ReplicatedStorage.WearHelmet.OnServerEvent:Connect(function(player, playername, itemtowear)	
	local Helmets = game.ReplicatedStorage.Helmets:GetChildren()
	local PlayerChildren = player:FindFirstChildWhichIsA("Model")
	for i, v in pairs(Helmets) do
		if PlayerChildren.Name == v then
			print(PlayerChildren)
		end
	end
end)

maybe try doing it like this it will use the helmets name and check inside the character of the player that fires the remote print if it finds something and removes its

game.ReplicatedStorage.WearHelmet.OnServerEvent:Connect(function(player, playername, itemtowear)	
	local Helmets = game.ReplicatedStorage.Helmets:GetChildren()
	local PlayerChildren = player.Character:GetChildren()
	for i, helmet in ipairs(Helmets) do
		local FoundHelmet = player.Character:FindFirstChild(helmet.Name)
		if FoundHelmet then 			-- might do a check to see if it IsA('Model') or Accessory what ever you use
			print('Found ' , FoundHelmet)
			FoundHelmet:Destroy()   -- remove the helmet
		end
	end
end)
1 Like

Thank you very much, it works!

1 Like

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