Hello. I am working on a sandbox but I need a build mode, so I made a local script but I keep getting "attempt to index nil with ‘KeyCode’ " on line 66, however, I cant figure out why.
local script
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(plr.Name)
local Cam = game.Workspace.CurrentCamera
Cam.CameraType = "Scriptable"
Cam.CFrame = CFrame.new(0,0,0)
local w,a,s,d,NotMoving = false,false,false,false,true
local function KeepMoving()
repeat
if w then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.UpVector * 0.4)
end
if s then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.UpVector * -0.4)
end
if a then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * -0.4)
end
if s then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * 0.4)
end
RS.RenderStepped:Wait()
until NotMoving
end
local function MoveBegan(actionName, inputState, input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if UIS:IsKeyDown(Enum.KeyCode.W) then
w = true
NotMoving = false
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
a = true
NotMoving = false
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
s = true
NotMoving = false
end
if UIS:IsKeyDown(Enum.KeyCode.D) then
d = true
NotMoving = false
end
if w and not s and not d and not a then
KeepMoving()
elseif s and not w and not d and not a then
KeepMoving()
elseif d and not w and not s and not a then
KeepMoving()
elseif a and not w and not d and not s then
KeepMoving()
end
end
end
local function moveEnded(input, gpe)
if input.KeyCode == Enum.KeyCode.W then
w = false
elseif input.KeyCode == Enum.KeyCode.A then
a = false
elseif input.KeyCode == Enum.KeyCode.S then
s = false
elseif input.KeyCode == Enum.KeyCode.D then
d = false
end
if not w and not s and not a and not d then
NotMoving = true
else
NotMoving = false
end
end
game:GetService("ContextActionService"):BindAction("MoveCam", MoveBegan,false,Enum.KeyCode.W,Enum.KeyCode.A,Enum.KeyCode.S,Enum.KeyCode.D)
UIS.InputEnded:Connect(moveEnded())