Why is this script not working?

Hello everyone, I’m trying to make a button that when pressed removes your hats/accessories, and this is the code:

script.Parent.MouseButton1Click:Connect(function()
	game.PlayerAdded:Connect(function(player)
		player.CharacterAppearanceLoaded:Wait()
		player.Character.Humanoid:RemoveAccessories()
	end)
end)

And this is where it’s placed (ScreenGUI)
image

Still learning how to script those type of stuff but hopefully I’ll learn something from this.
How can I fix this?

Thanks in advance!

game:GetService(“Players”).PlayerAdded

Also, you don’t need to hook this on an event, since it will not work. Just directly use player.CharacterAppearanceLoaded:Wait() player.Character.Humanoid:RemoveAccessories()

Just like this? I need it hooked to the button

script.Parent.MouseButton1Click:Connect(function()
	player.CharacterAppearanceLoaded:Wait() 
	player.Character.Humanoid:RemoveAccessories()
end)

Yes, just like that. The .PlayerAdded event will wait until a new Player joins the game, not immediately removing the accessories.

It needs to be game.Players.PlayerAdded

image
This is the error it gives me.

game.Players.PlayerAdded.MouseButton1Click:Connect(function()
	player.CharacterAppearanceLoaded:Wait() 
	player.Character.Humanoid:RemoveAccessories()
end)

Not like this, it should be…

script.Parent.MouseButton1Click:Connect(function()
	game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAppearanceLoaded:Wait()
		player.Character.Humanoid:RemoveAccessories()
	end)
end)

Doesn’t give any errors, but when I click tbe button it doesn’t do anything

It will wait until a player joins, what do you exactly want to do here?

When the player clicks a TextButton, the player hats get removed, sort of like a hat remover part but in a gui

Try this

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	player.CharacterAppearanceLoaded:Wait()
	player.Character.Humanoid:RemoveAccessories()
end)

I’ve put

script.Parent.MouseButton1Down:Connect(function ()

      game.ReplicatedStorage.RemoteEvent:FireServer()
end)

as a LocalScript in the textbutton,

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function (player)
       player.CharacterAppearanceLoaded:Wait()
       player.Character.Humanoid:RemoveAccessories()
end

in serverscriptserver,
and a remoteevent in replicatedstorage,

but still no errors in the console nor the button works

Did you try the script I gave you?

I did, it does the same thing, ive put that as a localscript in the text button, still no errors in the console tho

1 Like

Just test this hope this helped

image

script.Parent.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.Character.Humanoid:RemoveAccessories()
end)

It makes me spawn with no hats, but then they come back after a few seconds

I edited the script. (char limit bruh)