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

How do I stop an excecution of a coroutine after some time?

Asked by 8 years ago

I made this little script for my shop GUI

Here's my script

-- Inside Local Script
local UILib = require(game.Workspace:FindFirstChild("FadeModule"))
local Cam = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Detector = game.Workspace.Shop
local Head = Player.Character:WaitForChild("Head")
local Blind = Player.PlayerGui:WaitForChild("ShopUX"):FindFirstChild("Blind")
local Container = Player.PlayerGui:WaitForChild("ShopUX"):FindFirstChild("Container")

resetCam = function()
    game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end

positionCam = coroutine.create(function()
    while wait() do
        Cam.CameraType = Enum.CameraType.Scriptable
        Cam.Focus = game.Workspace.BasePlate.CFrame
        Cam.CoordinateFrame = CFrame.new(0,100,0)
    end
end)

Detector.Touched:connect(function(name)
    name = Player.Name
    game.Workspace:FindFirstChild("shopEvent"):FireServer(Player)
    Player.Character.Torso.Anchored = true
    UILib.Fade(Blind, "In", .1)
    Cam.CameraType = Enum.CameraType.Scriptable
    Cam.Focus = game.Workspace.BasePlate.CFrame
    Cam.CoordinateFrame = CFrame.new(0,100,0)
    wait(2)
    UILib.Fade(Blind, "Out", .1)
    Container.Visible = true
    UILib.Fade(Container, "In", .1)
    coroutine.resume(positionCam)
    UILib.Fade(Container, "Out", .1)
    Container.Visible = false
    resetCam()
end)

I problem here is that I want to reset the cam to our player, but how do i do this ? it seems like the coroutine is blocking me :(

0
You really don't want to be using a while loop. Why do you keep setting those properties repeatedly? 1waffle1 2908 — 8y
0
break User#5978 25 — 8y
0
corotine.yield stops a coroutine. 1waffle1 2908 — 8y
0
I'll try to rework on this script buoyantair 123 — 8y

Answer this question