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

camerascript not working, dont know problem?

Asked by 8 years ago

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

Log in to vote
0
Answered by
brianush1 235 Moderation Voter
7 years ago

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)

Ad

Answer this question