Player:GetAttributeChangedSignal("playbuttonclicked"):Connect(function()
if Player:GetAttribute("playbuttonclicked") == true then
typewriterthingy()
skipbutton.MouseButton1Click:Connect(function()
end)
end
end)
How do I stop “typewriterthingy” function from running once skipbutton is pressed?
local textLabel = script.Parent.mainText
local screengui = script.Parent
screengui.Enabled = false
local typesound = Instance.new("Sound")
typesound.SoundId = "rbxassetid://1394480679"
typesound.Looped = false
typesound.Parent = game.SoundService
local function introductionDialogueMain(object,text)
screengui.Enabled = true
for i = 1,#text,1 do
object.Text = string.sub(text,0.64,i)
typesound:Play()
wait(0.1)
end
end
local function typewriterthingy()
wait(3)
introductionDialogueMain(textLabel,"Welcome to Try To Die!",0.64)
wait(3)
introductionDialogueMain(textLabel,"The goal of this game is to die... but with a twist...",0.64)
wait(2)
introductionDialogueMain(textLabel,"have fun!!!",0.64)
wait(3)
screengui.Enabled = false
end
local skipbutton = screengui.skipbutton
Player = game.Players.LocalPlayer
connection = Player:GetAttributeChangedSignal("playbuttonclicked"):Connect(function()
skipbutton.MouseButton1Up:Connect(function()
return
end)
if Player:GetAttribute("playbuttonclicked") == true then
typewriterthingy()
end
end)
An easy way to cancel it would be running the function in a separate coroutine and cancelling this coroutine.
Player:GetAttributeChangedSignal("playbuttonclicked"):Connect(function()
if Player:GetAttribute("playbuttonclicked") == true then
local coroutineThread = task.spawn(typewriterthingy)
skipbutton.MouseButton1Click:Once(function()
task.cancel(coroutineThread)
end)
end
end)