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

Making my Camera brick move?

Hey guys (and gals)

I'm having trouble with remembering my basic Lua.. I need to have this brick move at a certain rate of speed. I've edited a previous script of mine that was for Gui's to try and make it work for Vector3, but to no avail.

Here it is:

main=script.Parent



if main.Position == CFrame.new(1485.6, 520.229, 1116.6) then
repeat
wait()
main.Position = main.Position + CFrame.new(0, 0, 25)	--speed
until main.Position  == CFrame.new(1485.6, 520.229, 1271.818)
end

Seems like I've just missed something, and I need a push in the right direction.

To clarify, I am only trying to move it on the Z axis for now.

Any help is appreciated, Thanks!

-Best Regards

Me

PS: If anyone can point me toward how to limit a player's ability to zoom out, that'd be excellent. trying to make a FPS

1 answer

✓ Accepted answer

You can't add a CFrame value to a Vector3 value, but you can add a Vector3 value to a CFrame value. You should change

main.Position = main.Position + CFrame.new(0, 0, 25)

to

main.CFrame = main.CFrame + Vector3.new(0, 0, 25)

or

main.CFrame = main.CFrame * CFrame.new(0, 0, 25)

depending on whether you want to translate the object from global / object coordinates.

Also, keep in mind the limitations of floating-point precision. Your script may or may not behave as expected when testing for equality of two CFrame values. You may find using a for loop to be more reliable in this situation.

1 comment

0

Appreciate the suggestion. Didn't work, maybe I interpreted it wrong, but I only changed that one line of code (line:8). I might attempt to change all places that say position to CFrame.. but since I'm a builder cooping with scripting, its like playing darts with a blindfold on. G'day!

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