0

I am making a hat dispenser, when inputted an id, the dispenser will equip the hat to the character of the player. I am using a serverside script and a RemoteFunction to gain access to InsertService from the client. Everything works fine, there are no errors, but when it gets to Humanoid:AddAccessory(), it doesn't equip the hat.

Server script:

game.ReplicatedStorage.Insert.OnServerInvoke = function(player, id)
print(a)
a.Parent = game.ReplicatedStorage
return a
end



Client Script:

local gui = script.Parent

gui.TextButton.MouseButton1Click:Connect(function()
print(tonumber(gui.TextBox.Text))
local acc = game.ReplicatedStorage.Insert:InvokeServer(tonumber(gui.TextBox.Text))
print(acc)
game.Players.LocalPlayer.Character.Humanoid:AddAccessory(acc:GetChildren()[1]) --This doesn't equip the hat.
end)


0
To elaborate further, it does equip the accessory, but the accessory is underneath the baseplate, stuck. This must be an attachment problem. TornadoCookie 20 — 13d
0
I have fixed it by moving everything that has to do with the accessory to the client. TornadoCookie 20 — 13d

0

It's not that Humanoid:AddAccessory() wasn't working, it was that the client has no memory of the server.

I fixed this by moving the line that calls Humanoid:AddAccessory() to the server, so now it looks like this:

Server Script:

game.ReplicatedStorage.Insert.OnServerInvoke = function(player, id)
print(a)
return a
end


Client Script:

local gui = script.Parent

gui.TextButton.MouseButton1Click:Connect(function()
print(tonumber(gui.TextBox.Text))
local acc = game.ReplicatedStorage.Insert:InvokeServer(tonumber(gui.TextBox.Text))
end)



Hope this helps anyone who stumbles upon this post.