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

How would I weld the hat into the players head?

Asked by 6 years ago

I was told I needed to weld the hat into the players head, although with that I have no actual idea how to weld things (I script GUIs and stuff but not items) How would I do this?

This is my script

local Player = game.Players.LocalPlayer

local HatsAvailable = {}

local Count = 0

local LeftButton = script.Parent.LeftHat

local RightButton = script.Parent.RightHat

for i,v in pairs(game.ReplicatedStorage.ClothingLow.HatsLow:GetChildren()) do
    table.insert(HatsAvailable,v)
end

function RemoveCurrentHats()
    for i,v in pairs(Player.Character:GetChildren()) do
        if v.ClassName == "Accessory" then
            v:Destroy()
            print("RIP HAT")
        end
    end
end


function Update()
    script.Parent.Buying.Value = true
    RemoveCurrentHats()
    script.Parent.ItemName.Text = HatsAvailable[Count].Name
    script.Parent.Price.Text = "$"..HatsAvailable[Count].Price.Value
    local HatTheyBoughtClone = HatsAvailable[Count]:Clone()
    HatTheyBoughtClone.Handle.HatAttachment.Position = Player.Character.Head.Position
    HatTheyBoughtClone.AttachmentPos = Player.Character.Head.Position
    HatTheyBoughtClone.AttachmentPoint = Player.Character.Head.CFrame
    Player.Character.Humanoid:AddAccessory(HatTheyBoughtClone)
end

script.Parent.LeftHat.MouseButton1Click:Connect(function()
    if Count >1 then
        Count = Count - 1
        Update()
    end
end)

script.Parent.RightHat.MouseButton1Click:Connect(function()
    if Count >= #HatsAvailable then
    else
        Count = Count + 1
        Update()
    end
end)

script.Parent.Parent.Decline.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent:Destroy()
end)

Like I said no actual idea how to weld anything

1 answer

Log in to vote
1
Answered by 6 years ago

If you need to weld the hat on then first you gotta create a new instance. Try putting this in

local HatTheyBoughtClone = HatsAvailable[Count]:Clone()
local WeldPiece = Instance.new("Weld") --create weld part
HatTheyBoughtClone.Handle.Position = Player.Character.Head.Position
WeldPiece.Part0 = Player.Character.Head --connects hat and head {
WeldPiece.Part1 = HatTheyBoughtClone
WeldPiece.C0 = CFrame.new(0, 0, 0)
WeldPiece.Parent = Player.Character.Head --}
Player.Character.Humanoid:AddAccessory(HatTheyBoughtClone)

Hope that answers your question :D

0
Thanks I can figure out how to reposition it Sergiomontani10 236 — 6y
Ad

Answer this question