Why isn't my hat giver working?

So I am working on a hat giver for my game, but the hat will not move to the players head, can someone explain why please?

function GiveHat(Character)
	Character.Humanoid:RemoveAccessories()
	
	local HatCFrame = CFrame.new(Character.Head.Position)
	local LookAt = CFrame.lookAt(Character.Head.Position, Character.Head.CFrame.LookVector)
	local MainCFrame = CFrame.new(HatCFrame, LookAt)
	
	local HatToGive = script.Parent.Main:Clone() HatToGive.Parent = Character
	HatToGive:SetPrimaryPartCFrame(MainCFrame)
end

Thanks for any help

1 Like

Your console might be able to explain why; and if not, then you should be able to do that. We can’t exactly handle the explaining part for you, that’s on you. We need context so we can better help you. Why does your hat giver not work? What’s the exact problem? Also, have you tried applying any basic debugging if it happens to be a script issue?

2 Likes

I dont know how to use roblox debugger, and the only error i get is:

Script:8: invalid argument #1 to ‘new’ (Vector3 expected, got CFrame)

1 Like

try this

function GiveHat(Character)
	Character.Humanoid:RemoveAccessories()
	
	local HatCFrame = Vector3.new(Character.Head.Position)
	local LookAt = CFrame.lookAt(Character.Head.Position, Character.Head.CFrame.LookVector)
	local MainCFrame = CFrame.new(HatCFrame, LookAt)
	
	local HatToGive = script.Parent.Main:Clone() HatToGive.Parent = Character
	HatToGive:SetPrimaryPartCFrame(MainCFrame)
end
1 Like

that gave another error,

Workspace.MTFHelmet.Script:8: invalid argument #2 to 'new' (Vector3 expected, got CFrame)

1 Like

CFrame.lookAt() also gives a position:

local function GiveHat(Character)
	Character.Humanoid:RemoveAccessories()
	local MainCFrame = CFrame.lookAt(Character.Head.Position, Character.Head.CFrame.LookVector)

	local HatToGive = script.Parent.Main:Clone() 
    HatToGive.Parent = Character
	HatToGive:PivotTo(MainCFrame)
end
1 Like

getting somewhere, now i just need to figure how how to make the fat face forwards. any idea how?

image

2 Likes

Also, sorry for my late reply, my studio crashed so I had to wait for a while to close it

2 Likes

In all honesty, you’re making it too complicated.
Literally just use a MainCFrame *= CFrame.Angles(math.rad(x), math.rad(y), math.rad(z)).

2 Likes

I dont understand where i put this

2 Likes

Anywhere under the MainCFrame variable.

X, Y, Z must be customized to your liking. It is rotation.

2 Likes