Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how to make click detectors detect when the player chats ?

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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
works perfectly MacGames007 114 — 3y
Ad

Answer this question