So a few things, first of all, I see nowhere where you are defining that the parent of the hat you defined, so you would have to put the character as the parent.
local hat = game.ReplicatedStorage.Helmet:Clone()
local Character = player.Character
hat.Parent = Character
You would need to define the player yourself, which I believe you should be able to do easily given your script.
I made something like this before too, and a problem I had was that the hat would just fall off the player, to fix this, I had to add in a "Weld" from the hat to the Characters head, so I will provide that code if needed.
local w = Instance.new("Weld", Character)
w.Part0 = hat
w.Part1 = Character.Head
If you still are having problems with the rotation/position of the hat, you would have to edit the accessory properties listed here:
AttachmentForward
AttachmentPos
AttachmentRight
AttachmentUp
For the hat remover, I would use Index and Values like this:
local d = Character:GetChildren()
for i = 1, #d do
if d[i]:IsA("Accessory") then
d[i].Handle.Transparency = 0
I would recommend using Transparency in case you want to remove the custom hat later, but otherwise just change the script to destroy the hats instead.
Please PM me or Comment on this if you have any questions!
Using all my suggestions, the code would look like this:
local Cash = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Money.Credits
local mcost = script.Parent.Cost.Value
local mname = script.Parent.Itemname.Value
function onClick()
if Cash.Value >= mcost then
Cash.Value = Cash.Value - mcost
local hat = game.ReplicatedStorage.Helmet:Clone()
local hat = game.ReplicatedStorage.Helmet:Clone()
local Character = player.Character
hat.Parent = Character
local w = Instance.new("Weld", Character)
w.Part0 = hat
w.Part1 = Character.Head
local d = Character:GetChildren()
for i = 1, #d do
if d[i]:IsA("Accessory") then
d[i].Handle.Transparency = 0
end
end
script.Parent.MouseButton1Click:connect(onClick)