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

Placing a hat on a character using a GUI with FilteringEnabled?

I'm creating a character customization menu for a custom player rig that's been rigged correctly and works swell. Upon the click of a button in a GUI, a hat is supposed to be cloned from a part and be given a mesh from a group called "meshes" in the lighting. The mesh applies to the hat just fine, and the hat spawns in, but it's supposed to parented to the player character. Instead, the hat spawns above the player and just falls onto the ground, unable to be picked up. I'm confused. The work is shown below.

function click()
	local player = game.Players.LocalPlayer
	local playername = player.Name
	local character = game.Workspace:FindFirstChild(playername)
	local children = character:GetChildren()

	-- This is where I spawn the hat.
	
	local hat3 = Instance.new("Hat")
	local part3 = Instance.new("Part")
	hat3.Name = "normalhair"
	part3.Parent = hat3
	part3.Position = character:FindFirstChild("Head").Position
	part3.Name = "Handle"
	part3.formFactor = 0
	part3.Size = Vector3.new(1, 1, 1)
	part3.BottomSurface = 0 
	part3.TopSurface = 0 
	part3.Transparency= 0
	part3.Locked = true 
	game.Lighting.meshes.normalhair:Clone().Parent = part3
	hat3.Parent = character
	hat3.AttachmentPos = Vector3.new(0, 0.15, -0.08)
end

script.Parent.MouseButton1Click:connect(click)

2 comments

0

Why did you turn the Locked property to true? I'm pretty sure they are going to change the permission level you need to access that with so you'll get an error, and it only affects studio.

0

Also, stop bullying the physics engine by doing calculations that you don't want to happen D: it never done anything to you besides fling you out of a map or few

1 answer

By going into studio, playing and then looking at hat structure I can see you missed the weld. http://prntscr.com/gtwr6z shows there are 2 extra objects in the handle. Small things like this can help find out why things dont work.

2 comments

0

I added a Weld to the Head and Part3 thanks to your help, and hats no longer slide off, but instead they aren't placed correctly on the head anymore, even with an AttachPos value. Any tips to fix this?

0

Anchor the player and the hat momentarily and then weld it maybe? If you weld after its on, it could slip out of place.

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