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

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

Asked by 5 years ago
Edited 5 years ago

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?

0
Check for errors in the output, or if you're testing it ingame check the developer console. Mr_Unlucky 1085 — 5y
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. Rheines 661 — 5y
0
Console error: "AddAccessory is not a valid member of Model", and this accessory should be visible to everyone 13kapi13 4 — 5y
0
Oh, you need to call AddAccessory on the Humanoid. So just swap it with humanoid:AddAccessory. Rheines 661 — 5y
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? 13kapi13 4 — 5y

1 answer

Log in to vote
0
Answered by
AbeTGT 4
3 years ago

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)
Ad

Answer this question