Coroutine not working after second time

  1. What do you want to achieve? I want to figure out how to resume coroutine for a second time.

  2. What is the issue? Coroutine doesn’t resume.

  3. What solutions have you tried so far? I couldn’t find any other solutions and I don’t know any either.

script.Parent.Triggered:Connect(function(player)
	local tb = script.Parent.Parent.talk:Clone()
	tb.Parent = player.PlayerGui
	local holder = tb.holder
	holder.npc.Visible = true
	holder.npc.Text = "test"
	holder.youbox.Visible = false
	holder.npcbox.Visible = true
	holder.Visible = true
	script.Parent.Enabled = false
	local istalking = false
	local talkcoro = coroutine.create(function()
	while istalking == true do
	script.Parent.Parent.CharacterUI.CharacterImage.ImageRectOffset = Vector2.new(24, 0)
	task.wait(0.1)
	script.Parent.Parent.CharacterUI.CharacterImage.ImageRectOffset = Vector2.new(0, 0)
	task.wait(0.1)
	end
	while istalking == false do
	task.wait(0.1)
	script.Parent.Parent.CharacterUI.CharacterImage.ImageRectOffset = Vector2.new(0, 0)
	end
	end)
	player.Character.HumanoidRootPart.Anchored = true
	local function AnimateText(Text)
		for i = 1, #Text, 1 do
			--script.Parent.Parent.CharacterUI:WaitForChild("CharacterImage").Image = "rbxassetid://122542649198426"
			script.Parent.Parent:WaitForChild("voice"):Play()
			tb:WaitForChild("holder").word.Text = string.sub(Text, 1, i)
			task.wait(0.05)
			--script.Parent.Parent.CharacterUI:WaitForChild("CharacterImage").Image = "rbxassetid://122542649198426"
		end
	end
	istalking = true
	coroutine.resume(talkcoro)
	AnimateText(script.Parent.Parent.say.Value)
	istalking = false
	holder.continuetalk.MouseButton1Click:Connect(function()
		holder.continuetalk.Visible = false
		if holder.word.Text == script.Parent.Parent.say.ans1.say.say.Value then
			tb:Destroy()
		end
	end)
	if holder.word.Text == script.Parent.Parent.say.Value then
		holder.option1.Visible = true
		holder.boxoption1.Visible = true
		holder.option1.Text = script.Parent.Parent.say.ans1.Value
	end
	holder.option1.MouseButton1Click:Connect(function()
		holder.option1.Visible = false
		holder.boxoption1.Visible = false
		istalking = true
		coroutine.resume(talkcoro)
		AnimateText(script.Parent.Parent.say.ans1.say.Value)
		holder.continuetalk.Visible = true
		istalking = false
	end)
	holder.continuetalk.MouseButton1Click:Connect(function()
		holder.continuetalk.Visible = false
		if holder.word.Text == script.Parent.Parent.say.ans1.say.Value then
			istalking = true
			coroutine.resume(talkcoro)
			AnimateText(script.Parent.Parent.say.ans1.say.say.Value)
			holder.continuetalk.Visible = true
			istalking = false
		end
	end)
end)

Here is what happens when I run it (The talking animation is supposed to play but doesn’t.).

The istalking value is never set to true.

Nevermind, istalking is being stopped before the animation ends which could cause problems.

The animation is a loop though.

Ah, you’re right. Allow istalking to control the loop independently of the text animation, meaning the animation can run in the background while text is being displayed, without interfering with eachotether

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.