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

Camera script not working?

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

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)

4 comments

0

Doesn't work, no errors either.

0

Odd, I think ROBLOX might've broken the mouse events again, but I don't know though.

0

Sorry, my parent is a textlabel XD.

0

Derp...

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