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

Where is the error in my script?

I'm trying to make the camera brick move forward,backwards,etc when a button is pressed.

I'm not exactly sure where the error is.

Player = script.Parent.Parent mouse = Player:GetMouse()

local var = game.Workspace.Cam local value = script.Parent.Value local x,y,z = value.x,value.y,value.z

function Forward1() x = x - 5 end

function Forward2() x = x + 5 end

function Forward() z = z - 5 end

function Forward3() z = z + 5 end

function onKeyDown(key) key = key:lower()

if key == "w" then
	Forward()
end
if key == "a" then
	Forward1()
end
if key == "s" then
	Forward2()
end
if key == "d" then
	Forward3()
end

end

mouse.KeyDown:connect(onKeyDown)

3 comments

0

Weird, my message glitched.

0

Fix it maybe?

0

Try using the CameraSubject instead.

1 answer

The problem is that x and z are local variables, whereas you need to modify the Camera's CoordinateFrame variable (and possibly the script.Parent.Value as well, if other scripts read from that). If you do x = script.Parent.Value.X and then x = x + 1, you haven't modified script.Parent.Value at all, you've just modified 'x'.

A simple fix would be to add:

local point = Vector3.new(x,var.CoordinateFrame.p.Y,z)
local lookPoint = point + var.CoordinateFrame.lookVector
var.CoordinateFrame = CFrame.new(point, lookPoint)

at the end of the OnKeyDown function.

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