debounce = true function onTouched(hit) if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then debounce = false h = Instance.new("Hat") p = Instance.new("Part") h.Name = "Hat" p.Parent = h p.Position = hit.Parent:findFirstChild("Head").Position p.Name = "Handle" p.formFactor = 0 p.CFrame = CFrame.new(0,0,0) * CFrame.Angles(0,math.pi,0) p.Size = Vector3.new(-0,-0,-1) p.CFrame=p.CFrame*CFrame.Angles(0,math.pi,0) p.BottomSurface = 0 p.TopSurface = 0 p.Locked = true script.Parent.Mesh:clone().Parent = p h.Parent = hit.Parent h.AttachmentPos = Vector3.new(0,1.75,-0.7) h.AttachmentRot = CFrame.new * CFrame.Angles(0,math.pi,math.pi/2) wait(5) debounce = true end end script.Parent.Touched:connect(onTouched)
This whole script works. It's supposed to clone the mesh of the parent brick of this script (in this case, a radio mesh) and then attach it to a players back. Everything is done right and it even attaches to my back in the place I wanted. However, it attaches backwards and is facing the wrong direction So I thought "Why don't I just change the CFrame of p to (0,math.pi,0) to turn it around completely?" When I added it into line 15, it seems to have no effect of the script. I tried copying and pasting line 15 into a normal brick and it seemed to rotate it just the way I wanted it to. Can anyone spot the problem?
There's not a real answer for this, you just have to mess around with the Angles until you get what you want.
But also look into using math.rad
and just normal numbers, rather than math.pi
Think about it like a circle;
math.rad(180) -- will flip it math.rad(380) --a whole revolution math.rad(90) --will half flip it.
The rad keyword stands for radians, radians are another word for degrees. So the number inside the math.rad function returns how many degrees you want your part to turn.