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

GUI button script that should add accessory to a player doesn't work, How can i fix that?

Hey everyone, I have a problem with my script. Basically the main function of this script is to add to a player custom accessory (DarkWings) from the ReplicatedStorage after player will click a gui button. For some reason it doesn't work, there might be problem with script that i created:

local playerModel = game.Players.LocalPlayer.Character
local humanoid = playerModel:WaitForChild("Humanoid")

script.Parent.MouseButton1Click:Connect(function()
if humanoid then
playerModel:AddAccessory(game.ReplicatedStorage.DarkWings)

end
end)

(I'm pretty new in scripting so there might some basic errors in this code) Edit.1 Console error: "AddAccessory is not a valid member of Model", and this accessory should be visible to everyone Edit.2 It works now, but there is now a problem with attachment accessory and clone function, in the handle of DarkWings model is already BodyBackAttachment but it doesn't work. Any idea how i can add clone function and attachment to this script?

5 comments

0

Check for errors in the output, or if you're testing it ingame check the developer console.

0

Is there any errors in the console? In addition, you might want to do it in a server script using remoteevents if you want to have the accessory visible for anyone.

0

Console error: "AddAccessory is not a valid member of Model", and this accessory should be visible to everyone

0

Oh, you need to call AddAccessory on the Humanoid. So just swap it with humanoid:AddAccessory.

0

Ah, it works now thanks! But there is now a problem with attachment accessory and clone function, in the handle of DarkWings model is already BodyBackAttachment but it doesn't work. Any idea how i can add clone function and attachment of this model?

1 answer

Two things.

  1. I recommend not using a LocalScript for this, I recommend using a server script.
  2. Don't set it to the character model, set it to the humanoid.

so instead of:

playerModel.AddAccessory(game.ReplicatedStorage.DarkWings)

do:

humanoid.AddAccessory(game.ReplicatedStorage.DarkWings)

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