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

Is there another way to get the positions for CFrame scripts?

What I mean is, I'm starting learning about CFrame and Vector3. THe only problem is, that when I type out the positions, I have to keep going into the properties of each brick, and then looking for it's position. Is there another way of doing this besides typing out every specific position? For example, this script I made here:

local button = game.Workspace.button		
local cf = game.Workspace.cfrme
local db = false


function move(hit)
	local human = hit.Parent
	if not db then
		if human then
			
			db = true
			
			for i = 21.1, 0.5, -0.1 do
			cf.CFrame = CFrame.new(Vector3.new(-1, 21.1, 71.7))
			cf.CFrame = CFrame.new(Vector3.new(-1, i, 71.7))
			wait(0.00001)
			
			end
			
			wait(3)
			for i = 0.5, 21.1, 0.1 do
				cf.CFrame = CFrame.new(Vector3.new(-1, 0.5, 71.7))
				cf.CFrame = CFrame.new(Vector3.new(-1, i, 71.7))
				wait(0.00001)
			end
			
			db = false
			
		end	
	end
end

button.ClickDetector.MouseClick:connect(move)

Everything works. I just want to know a different way to tell the script the positions. All help is appreciated!

1 answer

✓ Accepted answer

It's often better to phrase movement in terms of relative changes rather than setting the absolute position.

That means, e.g., rather than saying go from (-1, 21.7, 71.7) to (-1, 0.5, 71.7), you say "go down 21.2 studs from where you start".

Set it up so that cf starts at (-1, 21.7, 71.7). Then you script can just add relative amounts:

local start = cf.CFrame
for i = 0, 20.7, 0.1 do
	cf.CFrame = start + Vector3.new(0, -i, 0)
	wait(0.03)
end

start = cf.CFrame
for i = 0, 20.7, 0.1 do
	cf.CFrame = start + Vector3.new(0, i, 0)
	wait(0.03)
end

General notes on tidiness

It's best to write code that isn't misleading. wait doesn't care about very small numbers -- you should just use wait(0) if you want "a short time".

You shouldn't assign to cf twice in a row. If you want to leave an explanatory note, use comments! That's what comments are for!

Also, remember to tab your code correctly. Lines 13 to 15 are missing indentation.

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