Need help with a script

Hello :wave: , I started scripting not long ago and I’m trying to make a code that gives the player’s accessories to a dummy. Except that the problem is that I don’t understand why it doesn’t work (I put this code in a local script in a “text button”)

local dummy = game.Workspace.Effaceur_objets
local bouton = script.parent

bouton.MouseButton1Click:Connect(function(player)
	local d = player.Parent:GetChildren()
	for i=1, #d do
		if (d[i].className == "Accessory") then
			d[i].Parent = dummy
			print(i .. ' Objet donné au dummy ☑️')
		end
	end
end)

player.Parent.MouseButton1Click:Connect(player)

It works with part. ( don’t pay attention to the hair that has appeared)

2 Likes

Can you elaborate on the problem a bit more? What specifically isn’t working and do you get any errors?

player.Parent is game.Players, if you want to get the character then do player.Character

remove the line 14 because it makes no sense at all, you also already have a MouseButton1Click event at line 4

It’s good I deleted line 14 but now when I click on the button it does nothing.

You can try this since it’s a local script:

local dummy = game.Workspace.Effaceur_objets
local bouton = script.Parent
local player = game.Players.LocalPlayer

bouton.MouseButton1Click:Connect(function()
	local d = player.Character:GetChildren()
	for i=1, #d do
		if (d[i].className == "Accessory") then
			d[i].Parent = dummy
			print(i .. ' Objet donné au dummy ☑️')
		end
	end
end)

When I click on the button nothing happens, there are error messages.

I found the solution, Thanks for your help.

1 Like