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

How do I Weld a Hat to a Player's Head?

The script seems to work fine but When I'm trying to Weld the Hat to the Player's Head it doesn't seem to work. All it does is CFrame Hat into the Players Head But it Doesn't Weld it D: If you can help then I would appreciate it :)

local Player = game.Players.LocalPlayer
local Me = Player.Character
local Mouse = Player:GetMouse()

script.Parent.MouseButton1Click:connect(function()

	local Humanoid = Me:FindFirstChild("Humanoid")
if Humanoid then

for i,v in pairs (Me:GetChildren()) do
 if v:IsA("Pants") or v:IsA("Shirt") or v:IsA("CharacterMesh") or v:IsA("Hat") then
	v:remove()
end

if v:IsA("Part") then
	v.BrickColor = BrickColor.new("Mid gray")
end end 

print("Recoloured Part and Removed Junk")

for i,v in pairs (Me.Head:GetChildren()) do
if v:IsA("Decal") then
   v:remove()
end end

print("Remove Face Decal")

local A = Instance.new("Shirt", Me)
A.Name = "Shirt" 
A.ShirtTemplate = "http://www.roblox.com/asset/?id=227899193"

print("Added Shirt")

local B = Instance.new("Pants",Me)
B.Name = "Pants"
B.PantsTemplate = "http://www.roblox.com/asset/?id=188558593"

print("Added Pants")

local C = Instance.new("Decal",Me.Head)
C.Name = "face"
C.Texture = "http://www.roblox.com/asset/?id=133620200"

print("face Added")

local Hat = Instance.new("Hat", Me)
local Handle = Instance.new("Part", Hat)
	  Handle.Name = "Handle" 
Handle.Size = Vector3.new(1,1,1)
local Mesh = Instance.new("FileMesh", Hat.Handle)
Mesh.MeshId = "http://www.roblox.com/asset/?id=13070796"
Mesh.TextureId = "http://www.roblox.com/asset/?id=13070807"
--[[
----------------------------
===>WELDING<===
----------------------------
]]--

Hat.Handle.CFrame = Me.Head.CFrame

local Head = Me:FindFirstChild("Head")
local Weld = Instance.new("Weld")
Weld.Part0,Weld.Part1 = Head,Hat.Handle
Weld.C0 = CFrame.new(0,0.5,0)
Weld.C1 = Me.Head.AttachmentPoint

end end)

2 answers

✓ Accepted answer

I'm assuming you are using the Golden Hair hat from what you're using as the mesh.

You could get the actual hat object created by ROBLOX and parent it to somewhere like ReplicatedStorage, put this into your command bar in Studio:

game:GetObjects("rbxassetid://13476917")[1].Parent = game.ReplicatedStorage

From there, you could just clone the hat and set the parent to the player's character like so:

local hat = game.ReplicatedStorage.LongHairHeadBand:Clone() --If the name of the hat is different, change LongHairHeadBand to the name of the hat.
hat.Parent = Me

2 comments

0

Thank you !!!!!!!!!!!!

0

The script works fine it Edit Mode But it doesn't seem to work in-game, when I pressed f9 it came up with a error message saying Players.UserOnly16Characters.PlayerGui.ScreenGui.Frame.ImageButton.Cloth:6: attempt to index upvalue 'Me' (a nil value).

Parent the hat to the Player's character.

Your 'Me' appears nil to the code posted by @Spongocardo, because you have not used what you've defined in your script as "Me"

Don't get rid of your variables.

local Player = game.Players.LocalPlayer
local Me = Player.Character

2 comments

0

Thanks but I already have Defined my Variable and My script seem to Work in Play Solo but it doesn't work in Game.

0

Because your script is not a LocalScript

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