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

camerascript not working, dont know problem?

I am making a script in which when a value is changed by a button it brings the camera to a certain location. Script:

local plyr=game.Players.LocalPlayer
local cam=game.Workspace.CurrentCamera

wait(1)

local playergui=script.Parent
local EditMode=playergui.EditMode
local button1=playergui.Gui.Frame.Build

button1.MouseButton1Click:connect(function()
	EditMode.Value=true
	button1.Visible=false
end)

EditMode.Changed:connect(function(newvalue)
	if newvalue then
	        cam.CameraType=("Scriptable")
		cam.CFrame=(CFrame.new(3.57, 3.262, 3.358))
	end
end)

When I click on button1 in Studio it freezes, when I click on it ingame it does nothing.

1 answer

I was unable to replicate your error, but I believe this will work:

local plyr=game.Players.LocalPlayer
repeat wait() until game.Workspace.CurrentCamera -- Wait for camera to initialize
local cam=game.Workspace.CurrentCamera

wait(1)

local playergui=script.Parent
local EditMode=playergui.EditMode
local button1=playergui.Gui.Frame.Build

button1.MouseButton1Click:connect(function()
    EditMode.Value=true
    button1.Visible=false
end)

EditMode.Changed:connect(function(newvalue)
    if newvalue then
            cam.CameraType=("Scriptable")
        cam.CFrame=(CFrame.new(3.57, 3.262, 3.358))
    end
end)

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