Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my hat remover script not removing hats?

Script:

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
        wait()
		local d = chr:FindFirstChild("Hat")
		for i,v in pairs(d) do
        	v:Destroy()
        end
	end)
end)

1 answer

✓ Accepted answer

It isn't working because it is looking for a child inside the players character that is called "hat". Try this instead:

while wait() do
	for i,v in pairs(game.Players:GetPlayers()) do
		if workspace:FindFirstChild(v.Name) then
			local char = workspace:WaitForChild(v.Name)
			for i,v in pairs(char:GetChildren()) do
				if v.ClassName == "Hat" then
					v:Destroy()
				end
			end
		end
	end
end

4 comments

0

Doesn't work. :(

0

Okay I have changed the code, now see if it works.

0

Now it works. Thanks a lot.

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.