Debounce Issue - Chat NPC

Hello.

I am trying to make an NPC that talks using the in-game chat system and a chat bubble, similar to how a player uses the in-game chat.

However, both systems begin spamming as soon as the trigger is fired and overclocks my Events.
This is the debounce:

Help is appreciated.

Can you send over some more context?

I don’t know what you mean. I’m sorry.

You did it right, you just didn’t set it back. I like to use true to start,
so the check line is shorter. db to me always means debounce, again to keep it short.
It should have a pause too, it may not be (1). If I need it to be fast I’ll use (0.33)..

local db = true
script.Parent.Touched:Connect(function(hit)
	if db and hit.Name == "Torso" then db = false	
		game.ReplicatedStorage.BoulderChat.Ch_Visit:Fire()
		script.Parent.Parent.Jump.Value = false
		task.wait(1) db = true
	end
end)

Yours..

local debounce = false
script.Parent.Touched:Connect(function(hit)
	if not debounce then	
		if hit.Name == "Torso" then debounce = true
			game.ReplicatedStorage.BoulderChat.Ch_Visit:Fire()
			script.Parent.Parent.Jump.Value = false
			task.wait(1) debounce = false		
		end 
	end
end)

The debounce should be the first check as to avoid the rest.

I intentionally set the debounce to not set back, as it’s not meant to be activated again. I also made the trigger destroy itself when needed, albeit in a different script.

Ahhh.. well then take the.. task.wait(1) debounce = false out
Now it’s not a debounce it’s a trap or lockout.

Also it appeared to not work, strangely.

local event = game.ReplicatedStorage.BoulderChat.Ch_Health_Doubled
local event2 = game.ReplicatedStorage.BoulderChat.Ch_Visit
--local event2 = game.ReplicatedStorage.Event3
--local event3 = game.ReplicatedStorage.Event4
--local event4 = game.ReplicatedStorage.Event5
local Catalyst = game.ReplicatedStorage.BoulderChat.CATALYST
--local loop = false
--local loop1 = false

local function talk(msg)
	Catalyst:FireAllClients(msg, "ΑΣΤΕΡΙ ΔΙΑΒΟΛΟΣ", Color3.new(0.435294, 0.435294, 0.435294))
end

event.Event:Connect(function()
	talk("HEALTH HAS DOUBLED")
end)

event2.Event:Connect(function()
	talk("SOMEONE APPROACHES")
end)

This is the text chat system, responding code to the Ch_Visit:Fire(), and it may be causing the problem.
ignore the commentary text, as it was copy/pasted from an older version that I’m adapting to a newer version.
The text bubble chat also is affected, so here:

local cha = game:GetService("Chat")
event = game.ReplicatedStorage.BoulderChat.Ch_Health_Doubled
event2 = game.ReplicatedStorage.BoulderChat.Ch_Visit
event.Event:Connect(function()
	cha:Chat(script.Parent, "HEALTH HAS DOUBLED", Enum.ChatColor.White)
	game.ReplicatedStorage.BoulderChat.Ch_Health_Doubled:Fire()
	game.StarterPlayer.StarterCharacterScripts.SystemMessageTips.Enabled = true
	wait(5)
end)

event2.Event:Connect(function()
	cha:Chat(script.Parent, "SOMEONE APPROACHES", Enum.ChatColor.White)
	game.ReplicatedStorage.BoulderChat.Ch_Health_Doubled:Fire()
	game.StarterPlayer.StarterCharacterScripts.SystemMessageTips.Enabled = true
	wait(5)
end)

I’m now lost … you’ll have to fully explain what your goal is here.

Okay, so I am making an NPC that works similar to how a typical player would text in the chat system, having a text bubble and a display in the chat list. However, instead of firing normally once, it causes the entire chat to suddenly be flooded with the message that is fired by the event. The event(s) are significantly effected, so I thought it was the firing of the scripts that was causing the issue.

I was giving you the two systems involving the text chat list, and the chat bubble. The initial code I started with, the debounce code, is triggered by a brick being touched. However, despite this, the chat still proceeds to be flooded. The chat messages should only appear ONCE.

Still a bit lost..

local chat = game:GetService("Chat")
local bc = game.ReplicatedStorage:WaitForChild("BoulderChat")
local chHealth = bc:WaitForChild("Ch_Health_Doubled")
local catalyst = bc:WaitForChild("CATALYST")
local chVisit = bc:WaitForChild("Ch_Visit")

local function talkBubble(target,msg)
	chat:Chat(target,msg,Enum.ChatColor.White)
end

local function talkList(msg)
	catalyst:FireAllClients(msg,"ΑΣΤΕΡΙ ΔΙΑΒΟΛΟΣ",Color3.new(.435,.435,.435))
end

chHealth.Event:Connect(function()
	talkList("HEALTH HAS DOUBLED")
	talkBubble(script.Parent,"HEALTH HAS DOUBLED")
	game.StarterPlayer.StarterCharacterScripts.SystemMessageTips.Enabled = true
	task.wait(5)
end)

chVisit.Event:Connect(function()
	talkList("SOMEONE APPROACHES")
	talkBubble(script.Parent,"SOMEONE APPROACHES")
	game.StarterPlayer.StarterCharacterScripts.SystemMessageTips.Enabled = true
	task.wait(5)
end)

That any better? Some will say you don’t need to do that wait for ReplicatedStorage.
Myself I don’t move forward unless I’m sure I’m sure.. You don’t need to wait for ReplicatedStorage but that doesn’t mean the rest will not need a wait..

1 Like

That code is for the Text chat list, with the name of the NPC being “ΑΣΤΕΡΙ ΔΙΑΒΟΛΟΣ”, I won’t go into detail over it as it’s important in the game I am making. When the events shown above are fired, it makes the NPC say something.

Sorry for the confusion, I’m trying my best to answer.
Also, the code actually helped. However, the display shows the message twice. I’m trying to see what I can do with your code to solve that issue.

FINAL EDIT: Thank you! It works now.

1 Like

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