I am trying to make a system that explains the story to the player using a slideshow, but two text functions are overlapping and causing issues. How can I stop the current function and start the new one to prevent overlap?
-- Function
local function Text()
for i=1, #text do
script.Parent.TextLabel.Text = string.sub(text,1,i)
coroutine.wrap(soundPlay)()
wait(0.04)
end
end
-- Next Slide
script.Parent.Forward.MouseButton1Click:Connect(function()
CurrentSlide += 1
script.Parent.Back.Visible = true
if CurrentSlide == 5 then
humanoid.WalkSpeed = 16
player.CameraMode = Enum.CameraMode.LockFirstPerson
script.Parent.Parent.Visible = false
Events.GameStarted:FireServer()
end
script.Parent.StoryImage.Image = SlideImages[CurrentSlide]
text = SlideTexts[CurrentSlide]
Text()
end)
I have tried looking for a possible solution, but none have worked and I don’t know how I can fix this issue.