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

Calling another function inside a function and continuing it?

Asked by 6 years ago
local Player = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local Adventure = game.Workspace.Adventure
local Camera = workspace.CurrentCamera
local CameraPart = game.Workspace.CameraPart
local CameraPart = game.Workspace.CameraPart -- this is the Part we will move
local newPos = CameraPart.Position - Vector3.new(0,0,100) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.3 -- the Part will move 0.5 studs each time it moves
local Debounce = false
local Diff = newPos - CameraPart.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(CameraPart.Position, newPos).lookVector


function onStart()
    Player.ScreenGui.Start.Visible = true
    Adventure:Play()
    wait(1)
    for i = 1, 100 do
        Player.ScreenGui.Start.GoodEnough.TextTransparency = Player.ScreenGui.Start.GoodEnough.TextTransparency - 0.01
        wait(0.01)
    end
    wait(5)
    for i = 1, 100 do
        Player.ScreenGui.Start.GoodEnough.TextTransparency = Player.ScreenGui.Start.GoodEnough.TextTransparency + 0.01
        wait(0.01)
    end
    wait(2)
    for i = 1, 100 do
        Player.ScreenGui.Start.Sacrifice.TextTransparency = Player.ScreenGui.Start.Sacrifice.TextTransparency - 0.01
        wait(0.01)
    end
    wait(5)
    for i = 1, 100 do
        Player.ScreenGui.Start.Sacrifice.TextTransparency = Player.ScreenGui.Start.Sacrifice.TextTransparency + 0.01
        wait(0.01)
    end
    wait(2)
    Player.ScreenGui.Start.Visible = false
    onScriptable()
    MovePart()
    wait(1)
    for i = 1, 10 do
        Player.ScreenGui.Idk.TextTransparency = Player.ScreenGui.Idk.TextTransparency - 0.1
        wait(0.01)
    end
    wait(3)
    for i = 1, 10 do
        Player.ScreenGui.Idk.TextTransparency = Player.ScreenGui.Idk.TextTransparency + 0.1
        wait(0.01)
    end
    wait(0.5)
    for i = 1,10 do
        Player.ScreenGui.Determination.TextTransparency = Player.ScreenGui.Determination.TextTransparency - 0.1
        wait(0.01)
    end
    wait(3.5)
    for i = 1, 10 do
        Player.ScreenGui.Determination.TextTransparency = Player.ScreenGui.Determination.TextTransparency + 0.1
        wait(0.01)
    end
    wait(0.5)
    for i = 1, 10 do
        Player.ScreenGui.Might.TextTransparency = Player.ScreenGui.Might.TextTransparency - 0.1
        wait (0.01)
    end
    wait(1.5)
    Player.ScreenGui.Might.TextTransparency = 1
    Player.ScreenGui.Start.Visible = true
    wait(1)
    Player.ScreenGui.Start.Chapter.TextTransparency = 0
    wait(0.5)
    Player.ScreenGui.Start.Unknown.TextTransparency = 0
    wait(5)
    Player.ScreenGui.Start.Visible = false
end

function onScriptable()
    repeat wait()
        Camera.CameraType = Enum.CameraType.Scriptable
    until Camera.CameraType == Enum.CameraType.Scriptable
    for i = 1, 1000 do
        Camera.CFrame = CameraPart.CFrame
        wait(0.01)
    end
    Camera.CameraType = Enum.CameraType.Custom
end

function MovePart()
    if Debounce then return end -- end the function if debounce is true
    Debounce = true -- make Debounce true so the function can't run
    for n = 0, Mag, Increment do
        CameraPart.CFrame = CameraPart.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end
    Debounce = false -- set Debounce to false so the function can run again
end


onStart()

So my intention here is, while onStart is called, it will call onScriptable. However, I want the function to continue running after onScriptable is called, same when it calls MovePart. How do I do this? Thanks in advance.

1 answer

Log in to vote
0
Answered by
Troidit 253 Moderation Voter
6 years ago

From inside onStart, you can call spawn() where you want to call the function onScriptable like so:

function onStart()
    spawn(onScriptable())
    --Important code
end

function onScriptable()
    --Alternative code that needs ran at the same time.
end

More info here

0
That usage of spawn is incorrect. You are calling the function, which you shouldn't be. Avigant 2374 — 6y
0
Yeah it doesn't continue the function itself EzraNewLight 6 — 6y
Ad

Answer this question