Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this script work online?

Asked by 8 years ago

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)
0
Try adding "repeat wait until activeCamNo ~= nil" before line 15 (without quotes.) Spongocardo 1991 — 8y
0
Ah, thanks :) TehRandoms 0 — 8y

2 answers

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
8 years ago

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

Ad
Log in to vote
-1
Answered by
snow29 0
8 years ago

It says ~~~~~~~~~~~~~~~~~ active = false

Not~~~~~~~~~~~~~~~~~
activCamNo = false

:P

Answer this question