Hi all. I have been trying to get key input to work for my game, where the user controls the camera height with w/s or up arrow/down arrow. However, it is not working. Nothing happens at all. It is a localscript
Here is my code:
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local camball
local posspeed = 1.1
local negspeed = 0.9
local mouse = player:GetMouse()
local keys = {}
if workspace.Lots.Lot1.Value == player.Name then
cam.CameraSubject=workspace.CamBall1
camball = workspace.CamBall1
cam.CameraType = "Attach"
print(camball.Name) --This prints the name fine.
elseif workspace.Lots.Lot2.Value == player.Name then
cam.CameraSubject=workspace.CamBall2
camball = workspace.CamBall2
cam.CameraType = "Attach"
print(camball.Name)--This prints the name fine.
elseif workspace.Lots.Lot3.Value == player.Name then
cam.CameraSubject=workspace.CamBall3
camball = workspace.CamBall3
cam.CameraType = "Attach"
print(camball.Name)--This prints the name fine.
elseif workspace.Lots.Lot4.Value == player.Name then
cam.CameraSubject=workspace.CamBall4
camball = workspace.CamBall4
cam.CameraType = "Attach"
print(camball.Name)--This prints the name fine.
elseif workspace.Lots.Lot5.Value == player.Name then
cam.CameraSubject=workspace.CamBall5
camball = workspace.CamBall5
cam.CameraType = "Attach"
print(camball.Name)--This prints the name fine.
elseif workspace.Lots.Lot6.Value == player.Name then
cam.CameraSubject=workspace.CamBall6
camball = workspace.CamBall6
cam.CameraType = "Attach"
print(camball.Name)--This prints the name fine.
end
mouse.KeyDown:connect(function(key) keys[key] = true
if keys == keys["w"] or keys["\x11"] then
print("I actually do something")--This does NOT print anything at all
camball.Position.Y = camball.Position.Y * posspeed
elseif keys == keys["s"] or keys["\x12"] then
print("I actually do something too")--This does NOT print anything at all
camball.Position.Y = camball.Position.Y * negspeed
end
end)
mouse.KeyDown:connect(function(key) keys[key] = true
if keys == keys["w"] or keys["\x11"] then
posspeed = posspeed + 0.1
--negspeed = 1 - (posspeed - 1)
elseif keys == keys["s"] or keys["\x12"] then
negspeed = negspeed - 0.1
--posspeed = 1 + (1 - negspeed)
else
wait(1)
if keys == not keys["w"] or keys == not keys["\x11"] or keys == not keys["s"] or keys == not keys["\x12"] then
negspeed = 0.9
posspeed = 1.1
end
end
end)
coroutine.resume(coroutine.new(function()
while wait() do
cam.CoordinateFrame = CFrame.new(camball.Position) * CFrame.new(0, 0, -30)
end
end))
I then get this error:
19:57:55.427 - Workspace.Player1.LocalScript:73: attempt to call field 'new' (a nil value)
19:57:55.427 - Stack Begin
19:57:55.433 - Script 'Workspace.Player1.LocalScript', Line 73
19:57:55.433 - Stack End

1 comment
Do tab you code correctly, it makes it much easier to read especially with large amount of code. You're lucky you got answers at all.