Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid:AddAccessory() does not work?

Asked by 3 years ago

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) local a = game:GetService("InsertService"):LoadAsset(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 — 3y
0
I have fixed it by moving everything that has to do with the accessory to the client. TornadoCookie 20 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
    local a = game:GetService("InsertService"):LoadAsset(id)
    print(a)
    player.Character.Humanoid:AddAccessory(a:GetChildren()[1])
    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.

Ad

Answer this question