Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Where is the error in my script?

Asked by 9 years ago
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)

0
Weird, my message glitched. GammaGeek 0 — 9y
0
Fix it maybe? EzraNehemiah_TF2 3552 — 9y
0
Try using the CameraSubject instead. woodengop 1134 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

Ad

Answer this question