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

How do you break a loop remotely using a localscript?

Asked by 8 years ago

So, basically, I wanted to make a menu GUI.

I used this script to insert a localscript into my player:

game.Players.PlayerAdded:connect(function(player)
    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
end)

and then this is the localscript:

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

while wait() do
    camera.CoordinateFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 10, 5)
    angle = angle + math.rad(1)
end

Basically, this makes it so that the camera circles around the part in Workspace.

My idea is that once you press play, the camera returns to the player and you can walk around.

Here's the script inside the play button:

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

The problem is that once I "fix" the camera back to the player, it circles around the player because the loop is never broken.

I want it so that it stops circling around the player and the player can move their camera around freely, but I don't know how to break the loop remotely.

Please help, thanks.

0
Consider just disabling the camera script with the button script. That would do it. Or, stick a BoolValue somewhere accessible by both scripts: while cameraRotate.Value == true and wait() do TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Basically what TheDeadlyPanther said but turned into an answer

You could delete the script inside the player: game.Players.LocalPlayer.Character.LocalScript:Destroy()

Or you could make a boolvalue which constantly gets checked by the camera script

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

while script.Rotate.Value == true and wait() do
    camera.CoordinateFrame = CFrame.new(target.Position)
                           * CFrame.Angles(0, angle, 0)
                           * CFrame.new(0, 10, 5)
    angle = angle + math.rad(1)
end

Button click

script.Parent.MouseButton1Click:connect(function(plr)
game.Players.LocalPlayer.Character.LocalScript.Rotate.Value = false
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
end)

Ad

Answer this question