I’m back once again. This time is something i have no control over (at least i don’t think it is). Im a pretty lousy coder so any info is appreciated. But here is my issue, sorry im ranting.
I have a security system that works quite nicely. When you enter the cameras it takes your camera and places it inside the security cams around my level. If you press → (Right) or ← (Left) arrows on the keyboard It will add a 1 to an int value (between 0 and 21). Once on the number a while wait loop will then see the int number and snap you to the corresponding camera (I’ll provide the whole script for anyone who wishes to copy. Its not crazy amazing lol(some of the code was simplified but im sure yall will understand)). When you press the down arrow you are then released from the restricted cams and the int value gets set to 0.
The true problem lies here. When i enter the security cams again, and press arrow. It for some reason adds 2 instead of +1… so if i was on cam 1 it would jump to 3, 5, 7, 9 etc. Or if i leave again and re-enter it will then add 3 the next round (1,4,7,10 etc) AND I DON’T KNOW WHY? my code is probably a mess but literally ANY INFO is hella appreciated because I swear imma rip my hair out.
TL;DR – Camera seems to add an extra number each time I press the left or right arrows upon leaving and re-entering the security camera.
Code:
local Camera = game.Workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local Folder = game.Workspace.SecurityCams
local CamGUI = game.StarterGui.SecurityButtons
local Cam1 = Folder.SecurityCamA.Viewport
local Cam2 = Folder.SecurityCamB.Viewport
local Cam3 = Folder.SecurityCamC.Viewport
--- Removed for repetition but from Cam 4 - 19 its the same.
local Cam20 = Folder.SecurityCamT.Viewport
local Cam21 = Folder.SecurityCamU.Viewport
local player = game.Players.LocalPlayer
local CamInstance = Instance.new("NumberValue")
CamInstance.Parent = player
CamInstance.Value = 0
local A = false
game.ReplicatedStorage.SecurityCameraEvent.OnClientEvent:Connect(function()
A = false
CamInstance.Value = 0
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Cam1.CFrame
print(""..player.Name.." is on Cam 1")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Right then
CamInstance.Value = CamInstance.Value + 1
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Left then
CamInstance.Value = CamInstance.Value - 1
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Down then
Camera.CameraType = Enum.CameraType.Custom
CamInstance.Value = 0
A = true
if A == false then
Camera.CameraType = Enum.CameraType.Custom
CamInstance.Value = 0
end
end
end)
if A == false then
while wait(.1) do
if CamInstance.Value == 1 then
Camera.CFrame = Cam1.CFrame
print(""..player.Name.." is on Cam 1")
end
if CamInstance.Value == 2 then
Camera.CFrame = Cam2.CFrame
print(""..player.Name.." is on Cam 2")
end
if CamInstance.Value == 3 then
Camera.CFrame = Cam3.CFrame
print(""..player.Name.." is on Cam 3")
end
--- Removed for repetition but from 4 - 19 its the same.
if CamInstance.Value == 20 then
Camera.CFrame = Cam20.CFrame
print(""..player.Name.." is on Cam 20")
end
if CamInstance.Value == 21 then
Camera.CFrame = Cam21.CFrame
print(""..player.Name.." is on Cam 21")
end
if CamInstance.Value >= 22 then
Camera.CFrame = Cam1.CFrame
CamInstance.Value = 0
print(""..player.Name.." is at end of cam feed. Redirecting to cam 1")
end
if CamInstance.Value <= -1 then
Camera.CFrame = Cam1.CFrame
CamInstance.Value = 21
print(""..player.Name.." is at start of cam feed. Redirecting to cam 21")
end
end
end
UIS.InputBegan:Connect(function(input)
if CamInstance.Value >= 22 then
CamInstance.Value = 0
print(CamInstance.Value)
end
end)
end)
It’s a long read and I truly apologize but im honestly so lost. I clearly bit off WAY too much than i can chew…
Thank you anyone who is able to help! I really appreciate it :*)