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

Struggling can't figure it out about cam nil value.?

Asked by
korj5 0
8 years ago

ROBLOX Developer Console in ServerLog. 13:06:03 -- Players.korj5.PlayerGui.CameraBackground:44: attempt to index global 'cam' (a nil value) 13:06:03 -- Stack Begin 13:06:03 -- Script 'Players.korj5.PlayerGui.CameraBackground', Line 44 13:06:03 -- Stack End

On the point of line 44, I don't understand.

player = game.Players.LocalPlayer
player.StarterGear:WaitForChild("ID5")
function camera()
local cam = game.Workspace.Camera
cam.CameraSubject = game.Workspace.Camera
cam.CoordinateFrame = CFrame.new(game.Workspace.Camera2.Position)
cam.CameraType = "Scriptable"
cam.Focus = CFrame.new(35.8, 108.392, 532.006)
end
function decamera(newPlayer)
    wait(0.1)
    cam = game.Workspace.CurrentCamera
    cam.CameraSubject = newPlayer.Character.Humanoid
    cam.CameraType = "Custom"
end

camera()
player.StarterGear.ID5.Changed:connect(function(value)
    if value == true then
        decamera(player)
    elseif value == false then
        camera(player)
    end
end)


local guiObject = script.Parent.Parent.PlayerGui.GameStart.FullFrame.Scroll.Welcome.LeftFrame.HtP
local frame = script.Parent.Parent.PlayerGui.GameStart.FullFrame.Scroll.Welcome
local frame2 = script.Parent.Parent.PlayerGui.GameStart.FullFrame.Scroll.HtP
local t = script.Parent.Parent.PlayerGui.GameStart.FullFrame.Scroll.HtP.TextLabel


guiObject.MouseButton1Click:connect(function()
  for i = 1,50 do
    frame.Position = frame.Position + UDim2.new(0.02,0,0,0)
    wait(0.005)
    end
  for i = 1,35 do
    frame2.Position = frame2.Position + UDim2.new(0,0,-0.02,0)
    wait(0.005)
    end
    wait(2)

cam.CameraSubject = game.Workspace.ss1
cam.CoordinateFrame = CFrame.new(game.Workspace.ss1.Position)
cam.Focus = CFrame.new(game.Workspace.sss1.Position)
t.Text = "Welcome to Fort Azzuron II, Axeums's first fortress. This tutorial will show you exactly how to play, along with giving you tips in the end."
wait(10)
cam.CameraSubject = game.Workspace.ss2
cam.CoordinateFrame = CFrame.new(game.Workspace.ss2.Position)
cam.Focus = CFrame.new(game.Workspace.sss2.Position)
t.Text = "To start off with the raider spawn, raiders (Just like the Axeum team) spawn in dropships to avoid spawn killing. In the dropship you can access the shop to buy primary weapons."
wait(10)
t.Text = "Once ready, raiders may drop down to the base underneath them and choose to either fight above ground, or under ground."
wait(8)
cam.CameraSubject = game.Workspace.ss3
cam.CoordinateFrame = CFrame.new(game.Workspace.ss3.Position)
cam.Focus = CFrame.new(game.Workspace.sss3.Position)
t.Text = "If you're fighting above ground, the only way to get inside is from the tunnels off to the left side, or by getting through the gate shields."
wait(10)
cam.CameraSubject = game.Workspace.ss4
cam.CoordinateFrame = CFrame.new(game.Workspace.ss4.Position)
cam.Focus = CFrame.new(game.Workspace.sss4.Position)
t.Text = "If you're fighting underground, it is a straight shot to the inside of the base, but watch out for traps!"
wait(8)
cam.CameraSubject = game.Workspace.ss5
cam.CoordinateFrame = CFrame.new(game.Workspace.ss5.Position)
cam.Focus = CFrame.new(game.Workspace.sss5.Position)
t.Text = "At the gate shields, the gate terminal is your key to getting inside. It holds 5000 health on both sides. Once dead, the shield on the terminal's side will open. CAUTION: It repairs itself in 5 minutes if the health drops below 4000!"
wait(13)
cam.CameraSubject = game.Workspace.ss6
cam.CoordinateFrame = CFrame.new(game.Workspace.ss6.Position)
cam.Focus = CFrame.new(game.Workspace.sss6.Position)
t.Text = "This is the Core Reactor. It's health is 30,000; which seems like a massive amount. Once it hits 0, the raiders win. The key to winning is by teamwork! Use it to your advantage, or you will not win!"
wait(14)
cam.CameraSubject = game.Workspace.ss7
cam.CoordinateFrame = CFrame.new(game.Workspace.ss7.Position)
cam.Focus = CFrame.new(game.Workspace.sss7.Position)
t.Text = "Amplus Legion spawns in the valley over there. Though it might seem like they spawn close to the base, it is a pretty far walk from where they actually spawn at."
wait(10)
t.Text = "This is the end to the tutorial, Good luck to you if you're a raider!"
wait(5)
t.Text = ""
 for i = 1,35 do
    frame2.Position = frame2.Position + UDim2.new(0,0,0.02,0)
    wait(0.005)
    end
 for i = 1,50 do
    frame.Position = frame.Position + UDim2.new(-0.02,0,0,0)
    wait(0.005)
    end
end)

0
You put cam as local value in a function so it's not recognized outside the function as a variable. BobserLuck 367 — 8y
0
It's game.Workspace.CurrentCamera, not Camera TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

You've never defined cam!

Your definition inside the camera() function is local -- it is local to that function, and is not usable by code outside that function.

It is good practice to mark variable definitions with local even when their scope is going to be the whole program, but you need to make sure your definition includes everywhere it's used -- it needs to be defined before function camera() so that it can be used after function camera()'s end.


You should tab your code correctly!

I also recommend using tables or functions to shorted how much you retype in each of the instructional lines.

0
Thank you so much,!! korj5 0 — 8y
Ad

Answer this question