Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make click detectors detect when the player chats ?

ok so the tile explains itself, i want to make that when the player click the part a dialogue pops up (done) but to response the dialogue u need to type in chat, but it just detects the message multiple times

code:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
repeat wait until plr.Chatted

plr.Chatted:Connect(function(msg)
	if msg == "yes" then
		print("test")
	end
end)

when i use it once, it works perfectly fine, but when i talk to him again, it fires twice.

1 answer

✓ Accepted answer

I think it just keeps making event listeners so the solution would be to disconnect events as such:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
repeat wait() until plr.Chatted
local connection
connection = plr.Chatted:Connect(function(msg)
    if msg == "yes" then
        print("test")
	connection:Disconnect()
    end
end)

1 comment

1

works perfectly

This discussion is preserved as it was. New answers, comments, and votes are closed.