Hey there, new scripter here.
I'm making a short story based game similar to the likes of Camping ect,
And was wondering if there is a way to "Pause" a gui/code from carrying on until i manually call for it?
Right now im just using wait()'s and putting in random seconds but i need something more reliable?
Once these 3 strings are finished i want it to be "Paused" until i Touch a part which will carry on the script when i add more Strings to it later
-- Roblox services local dialogGui = script.Parent local ReplicatedStorage = game:GetService("ReplicatedStorage") local object = script.Parent -- Require module local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter")) wait(0.1) TypeWriter.typeWrite(script.Parent, "Welcome students, I hope you enjoy your stay!") wait(1) TypeWriter.typeWrite(script.Parent, "Why don’t you get started by heading upstairs for some classes") wait(1) TypeWriter.typeWrite(script.Parent, "It’s the first door on the left") wait(1) object.AnchorPoint = Vector2.new(0, 0) object.Position = UDim2.new{0, 0},{0, 0} object:TweenPosition(UDim2.new(0, 0, -10.04, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine,0.5) wait(2) script.parent.Visible = false if script.parent.visible == false then print("Worked!") end
Thanks,
Doing what you want is a bit more complicated than it would seem.
To accomplish it, you need to use coroutines. All these are are ways to run different tasks/code at the same time, even if one stops to wait for something. Here's the gist of what you want to do:
local myCoroutine = coroutine.running() local brick = script.Parent function continueColorChange() coroutine.resume(myCoroutine) end brick.Touched:Connect(continueColorChange) --Things below here will be paused-- coroutine.yield() brick.Color = Color3.new(1,0,0) coroutine.yield() brick.Color = Color3.new(0,1,0) coroutine.yield() brick.Color = Color3.new(0,0,1)
This script, when parented to a brick, will incrementally change its colors to the ones we set every time it is touched, pausing in between each color change. It's a different outcome but the same concept you want to achieve. Let's go through it. The first thing we do is get the entire script's coroutine. This coroutine will allow us to control when the script is running and when it isn't.
local myThread = coroutine.running()
Then, we link an event to resume the script when something happens that we want to restart the script once it is paused (In this case, touching the brick). coroutine.resume() restarts the main script's coroutine "myCoroutine" after it is paused.
function continueColorChange() coroutine.resume(myThread) end brick.Touched:Connect(continueColorChange)
Finally, we get to the part that will be executed sequentially. Everytime "coroutine.yeild()" is called, it pauses execution of the script until coroutine.resume() is called - in this case by the event linked to the brick touch event.
coroutine.yield() brick.Color = Color3.new(1,0,0) coroutine.yield() brick.Color = Color3.new(0,1,0) coroutine.yield() brick.Color = Color3.new(0,0,1)
If you want some more examples and explinations, you can look at the coroutine tutorial here.