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

Simple CFrame isn't working?

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?

1 answer

✓ Accepted answer

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.

2 comments

0

So instead of using what I used in line 15, I'd instead use p.CFrame=p.CFrame*CFrame.Angles(0,math.rad(180),0), correct? Since there is pi radians in half a circle, this would theoretically flip it about the y axis and make it face the right direction

0

Supposedly, yes. But I don't know the exact dimensions of your part or where it is relative to the character so just try messing around with the numbers.

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