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

Attempt To Call A Nil Value?

I'm making an FNaF game on Roblox and I put two Camera Blocks and I also put a GUI button to switch Cameras but It says "Attempt To Call A Nil Value"

Here's the code:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local TurnButton = game.StarterGui.TurnGUI.TurnButton


function onClick()
	repeat wait()
		Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable
	Camera.CFrame = workspace.CameraPOV2.CFrame
end
script.Parent.MouseButton1Click:connect()

Can someone please help me?

4 comments

0

Is it a localscript?

0

Yes it is

0

I put it in the guibutton

0

The way to access a gui should be though script.Parent then blah blah or player:WaitForChild("PlayerGui") then your info, StarerGui is where the base guis are but the guis a player sees is replicated into a folder in the player called PlayerGui

1 answer

✓ Accepted answer

If you want the button to work use this instead, you never told the script what to do when the button was pressed. Though you made a function, the function was never fired meaning, the script has an error, due to no end.

script.Parent.MouseButton1Click:connect(onClick()

4 comments

0

There's a syntax error could you possibly put in the whole script in? Just to make sure

0

Sorry I fixed it you you don't put do script.Parent.MouseButton1Click:connect(onClick() you do ,script.Parent.MouseButton1Click:connect(onClick)

0

:Connect()*

0

You should also mention how TurnButton is referenced incorrectly and how they'll experience replication issues.

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