The localscript works fine in solo, but online it says that 'activCamNo' does not exist. I'm confuzzled.
local p= script.Parent.Parent.Parent --game.Players.LocalPlayer local char= p.Character local cam= workspace.CurrentCamera local camList= { workspace.Cam1.Viewpoint, workspace.Cam2.Viewpoint, workspace.Cam3.Viewpoint } local activCam= 1 local activCamNo= Instance.new("IntConstrainedValue") activCamNo.Name= "CamNo" activCamNo.Parent= script.Parent active= false function checkCamNo() activCamNo.MaxValue= #camList activCamNo.MinValue= 0 if activCamNo.Value== 0 then active= false activCam= char.Humanoid elseif activCamNo.Value~= 0 then active= true activCam= camList[activCamNo.Value] end end checkCamNo() game:GetService('RunService').Stepped:connect(function() checkCamNo() if active== false then cam.CameraType= "Custom" char.Humanoid.WalkSpeed= 10 elseif active== true then cam.CameraType = 'Scriptable' cam.CoordinateFrame = CFrame.new(activCam.Position, CFrame.new(activCam.CFrame * Vector3.new(0,0,-1)).p) char.Humanoid.WalkSpeed= 0 else end end)
In-order to prevent from "Scripts not working online" use the YieldFunction
, WaitForChild
or repeat wait() until Object_name
.
What is WaitForChild()?
What does it do?
The YieldFunction WaitForChild
yields to the current thread until a child with the given title is found, if Not, then your code will not run at all.
local p= script.Parent.Parent.Parent --game.Players.LocalPlayer local char= p.Character local cam= workspace.CurrentCamera local camList= { workspace.Cam1.Viewpoint, workspace.Cam2.Viewpoint, workspace.Cam3.Viewpoint } local activCam= 1 local activCamNo= Instance.new("IntConstrainedValue") activCamNo.Name= "CamNo" activCamNo.Parent= script.Parent repeat wait() until activCamNo active= false function checkCamNo() activCamNo.MaxValue= #camList activCamNo.MinValue= 0 if activCamNo.Value== 0 then active= false activCam= char.Humanoid elseif activCamNo.Value~= 0 then active= true activCam= camList[activCamNo.Value] end end checkCamNo() game:GetService('RunService').Stepped:connect(function() checkCamNo() if active== false then cam.CameraType= "Custom" char.Humanoid.WalkSpeed= 10 elseif active== true then cam.CameraType = 'Scriptable' cam.CoordinateFrame = CFrame.new(activCam.Position, CFrame.new(activCam.CFrame * Vector3.new(0,0,-1)).p) char.Humanoid.WalkSpeed= 0 else end end)
Don't be discombobulated with FindFirstChild
It says ~~~~~~~~~~~~~~~~~ active = false
Not~~~~~~~~~~~~~~~~~ activCamNo = false
:P