Bug with dialog system / Not resolved

Hello, i was making a dialog system. But it don’t work correctly.

If you see, they talk a double time in the same time.

Here the code :

local GUI = script.Parent
local Frame = GUI.Frame
local NameOfT = Frame.NameOfTalker
local DiscussionText = Frame.Message
local ContinueMessage = Frame.ContinueMessage

local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()

local ShopEvent = game.ReplicatedStorage.EnterShop

local TweenService = game:GetService("TweenService")
local PlayerCamera = game.Workspace.CurrentCamera
local CameraFolder = game.Workspace.Cameras
local ShopCamFolder = CameraFolder.Shop

local FinishTalking = false

local function TypeWritingEffect(text, talker)
	local FINISH = false
	for i = 1, #text do
		DiscussionText.Text = string.sub(text, 1, i)

		if talker == 1 then
			GUI.Bill:Play()
		end
		if talker == 2 then
			GUI.Flora:Play()
		end
		print(FinishTalking)
		wait(0.05)
		if DiscussionText.Text == text then
			FINISH = true
			print("TEXT FINISH")
		end
	end
	if FINISH == true then
		FinishTalking = true
	end
end

local KeyToContinue = Enum.KeyCode.Space

local ContinueDiscussion = false

local CameraTweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

local LastCameraCFrame

local FiredEvent = false

ShopEvent.OnClientEvent:Connect(function(Prompt)
	Character.PrimaryPart.Anchored = true
	Prompt.Enabled = false
	Frame.Visible = true

	LastCameraCFrame = PlayerCamera.CFrame

	PlayerCamera.CameraType = Enum.CameraType.Scriptable
	TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = ShopCamFolder.Cam1.CFrame}):Play()

	FinishTalking = false
	NameOfT.Text = "Bill"
	local MerchandTalk = math.random(1,5)
	if MerchandTalk == 1 then
		TypeWritingEffect("Hello !", 1)
	elseif MerchandTalk == 2 then
		TypeWritingEffect("Welcome !", 1)
	elseif MerchandTalk == 3 then
		TypeWritingEffect("It is a beautiful day :)", 1)
	elseif MerchandTalk == 4 then
		TypeWritingEffect("Hello "..Player.DisplayName.." !", 1)
	elseif MerchandTalk == 5 then
		TypeWritingEffect("Flora is mad today !", 1)
	end

	repeat wait() until FinishTalking == true

	ContinueDiscussion = false
	ContinueMessage.Visible = true

	UIS.InputBegan:Connect(function(keycode)
		if keycode.KeyCode == KeyToContinue then
			ContinueDiscussion = true
		end
	end)

	Mouse.Button1Down:Connect(function()
		ContinueDiscussion = true
	end)

	repeat wait() until ContinueDiscussion == true
	DiscussionText.Text = ""

	ContinueMessage.Visible = false
	TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = ShopCamFolder.Cam2.CFrame}):Play()

	FinishTalking = false
	NameOfT.Text = "Flora"
	local FloraTalk = math.random(1,5)
	if FloraTalk == 1 then
		TypeWritingEffect("Oh, you are here :)", 2)
	elseif FloraTalk == 2 then
		TypeWritingEffect("Flowers are peace <3", 2)
	elseif FloraTalk == 3 then
		TypeWritingEffect("Beautiful garden you have !", 2)
	elseif FloraTalk == 4 then
		TypeWritingEffect("I'm so happy today", 2)
	elseif FloraTalk == 5 then
		TypeWritingEffect("I'm better than Bill", 2)
	end

	repeat wait() until FinishTalking == true

	ContinueDiscussion = false
	ContinueMessage.Visible = true

	UIS.InputBegan:Connect(function(keycode)
		if keycode.KeyCode == KeyToContinue then
			ContinueDiscussion = true
		end
	end)

	Mouse.Button1Down:Connect(function()
		ContinueDiscussion = true
	end)

	repeat wait() until ContinueDiscussion == true
	ContinueMessage.Visible = false
	DiscussionText.Text = ""

	TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = ShopCamFolder.Cam3.CFrame}):Play()

	game.ReplicatedStorage.InShop:FireServer(true)

	Frame.Visible = false

	game.ReplicatedStorage.InShop.OnClientEvent:Connect(function(Statut)
		if Statut == false then
			print("FIRED !!!!!!")
			print(Statut)
			Frame.Visible = true

			TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = ShopCamFolder.Cam1.CFrame}):Play()

			FinishTalking = false
			NameOfT.Text = "Bill"
			local MerchandTalk2 = math.random(1,5)
			if MerchandTalk2 == 1 then
				TypeWritingEffect("Goodbye !", 1)
			elseif MerchandTalk2 == 2 then
				TypeWritingEffect("Thank, see you next time", 1)
			elseif MerchandTalk2 == 3 then
				TypeWritingEffect("You leave now ? :(", 1)
			elseif MerchandTalk2 == 4 then
				TypeWritingEffect("Goobye "..Player.DisplayName.." !", 1)
			elseif MerchandTalk2 == 5 then
				TypeWritingEffect("Flora will be sad", 1)
			end

			repeat wait() until FinishTalking == true

			ContinueDiscussion = false
			ContinueMessage.Visible = true

			UIS.InputBegan:Connect(function(keycode)
				if keycode.KeyCode == KeyToContinue then
					ContinueDiscussion = true
				end
			end)

			Mouse.Button1Down:Connect(function()
				ContinueDiscussion = true
			end)

			repeat wait() until ContinueDiscussion == true
			ContinueMessage.Visible = false
			DiscussionText.Text = ""
			TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = ShopCamFolder.Cam2.CFrame}):Play()

			FinishTalking = false
			NameOfT.Text = "Flora"
			local FloraTalk2 = math.random(1,5)
			if FloraTalk2 == 1 then
				TypeWritingEffect(":(", 2)
			elseif FloraTalk2 == 2 then
				TypeWritingEffect("Be kind with all flowers", 2)
			elseif FloraTalk2 == 3 then
				TypeWritingEffect("Goodbye", 2)
			elseif FloraTalk2 == 4 then
				TypeWritingEffect("See you next time !", 2)
			elseif FloraTalk2 == 5 then
				TypeWritingEffect("I want you to hydrate all thirsty flowers !", 2)
			end

			repeat wait() until FinishTalking == true

			ContinueDiscussion = false
			ContinueMessage.Visible = true

			UIS.InputBegan:Connect(function(keycode)
				if keycode.KeyCode == KeyToContinue then
					ContinueDiscussion = true
				end
			end)

			Mouse.Button1Down:Connect(function()
				ContinueDiscussion = true
			end)

			repeat wait() until ContinueDiscussion == true
			ContinueMessage.Visible = false
			DiscussionText.Text = ""

			local LastTween = TweenService:Create(PlayerCamera, CameraTweenInfo, {CFrame = LastCameraCFrame})
			LastTween:Play()
			Frame.Visible = false

			LastTween.Completed:Wait()
			PlayerCamera.CameraType = Enum.CameraType.Custom

			Prompt.Enabled = true
			Character.PrimaryPart.Anchored = false
		end
	end)
end)

Help me : (

Change that to this

local function TypeWritingEffect(text, talker)
	if FinishTalking ~= true then
		local FINISH = false
		for i = 1, #text do
			DiscussionText.Text = string.sub(text, 1, i)
			
			if talker == 1 then
				GUI.Bill:Play()
			end
			if talker == 2 then
				GUI.Flora:Play()
			end
			print(FinishTalking)
			wait(0.05)
			if DiscussionText.Text == text then
				FINISH = true
				print("TEXT FINISH")
			end
		end
		if FINISH == true then
			FinishTalking = true
		end
	end
end

It don’t work, i don’t know what I should do…

What was your idea ? Do you have a solution ? Maybe ?

Looks to me like the InShop remote is being fired multiple times, add some kind of debounce to it so the remote cannot be fired by the same player until the dialogue is finished.

It don’t work, i made a value that need to be false to execute the dialog.

Could you send that part of the code?

The code that receive the event or the code that send the event ?

The code that sends the event with the debounce you added.

game.ReplicatedStorage.InShop.OnServerEvent:Connect(function(plr, Statut)
	local debounce = false
	if not debounce then
		debounce = true
		if Statut == true then
			game.ReplicatedStorage.InShop:FireClient(plr, true)
		else
			game.ReplicatedStorage.InShop:FireClient(plr, false)
		end
		debounce = false
	end
end)

There should be a debounce on the client script as well, to my knowledge FireClient does not pause the script from running until the client script is done so that debounce is only around for a short amount of time. And from the looks of the video you sent something is definitely causing the remote to run twice.

I’ve made a print in the code that receive, but the print is here 1 time, not a multiple of time

Use remote function instead. This will wait until the function is finished.