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

Camera script not working?

Asked by
Relatch 550 Moderation Voter
9 years ago

When you click the button that the script is parented to, it doesn't seem to make the camera normal again. It just keeps circling the part in workspace. Why is this?

local target = workspace.Part
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0

while true do
    camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, 20)
    angle = angle + math.rad(0.8)
    game:GetService("RunService").RenderStepped:wait()
end

script.Parent.MouseButton1Down:connect(function()
    game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end)

1 answer

Log in to vote
0
Answered by 9 years ago

Make a variable to control when the while loop runs. Then, make an if statement in the while loop to check if the variable is false.

If the variable is false, run the camera changing code. Else, do nothing.

local target = workspace.Part
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0
local disabled = false

while true do
    if not disabled then
        camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, 20)
        angle = angle + math.rad(0.8)
    end
    game:GetService("RunService").RenderStepped:wait()
end

script.Parent.MouseButton1Down:connect(function()
    disabled = true
    game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end)

0
Doesn't work, no errors either. Relatch 550 — 9y
0
Odd, I think ROBLOX might've broken the mouse events again, but I don't know though. Spongocardo 1991 — 9y
0
Sorry, my parent is a textlabel XD. Relatch 550 — 9y
0
Derp... Spongocardo 1991 — 9y
Ad

Answer this question