Script not rotated properly

So my script is suppose to rotate the hat when the hat is given but it will not rotate, I have tried CFrame.Angles, p.Rotation = Vector3.new and they do not work, Help me on this.

		debounce = true
function onTouched(hit)
	if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
		debounce = false
		h = Instance.new("Hat")
		p =  script.Parent.Parent.Hat.Helmet2:clone()
		p.WeldConstraint:Destroy()
		h.Name = "Helmet"
		p.Parent = h
		p.Rotation = Vector3.new(0,90,0)
		p.Position = hit.Parent:findFirstChild("Head").Position
		p.Name = "Handle" 
		p.BottomSurface = 0 
		p.TopSurface = 0 
		p.Locked = true 
		h.Parent = hit.Parent
		h.AttachmentPos = Vector3.new(0, 0.3, 0)
		script.Parent.BrickColor = BrickColor.new("Bright red")
		wait(5)
		debounce = true
		script.Parent.BrickColor = BrickColor.new("Bright blue")
	end
end

script.Parent.Touched:connect(onTouched)


This is what it does

try doing something in this format:
p.CFrame = hit.Parent.Head.Position + CFrame.Angles(math.rad(45), 0, 0)

it’ll probably take some tweaking to get the position and rotation correct, but this is usually how I go about those types of things.

1 Like

Error: Workspace.Hat1.Touch.Script:10: invalid argument #1 (CFrame expected, got Vector3)

Taking position values from a Part instance will return a Vector3, which isn’t too compatible with CFrames. Try ‘hit.Parent.Head.CFrame’ or ‘hit.Parent.Head.CFrame.Position’ instead.

It is still not rotated, I have no idea why it is not rotating

Nvm it finally fixed it. After researching a lot.