Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't this script work online?

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)

2 comments

0

Try adding "repeat wait until activeCamNo ~= nil" before line 15 (without quotes.)

0

Ah, thanks :)

2 answers

✓ Accepted answer

Prevention

In-order to prevent from "Scripts not working online" use the YieldFunction, WaitForChild or repeat wait() until Object_name.

WaitForChild

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.

Fixed Code

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

This discussion is preserved as it was. New answers, comments, and votes are closed.