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

Wait for user chatted response? [solved]

Asked by 5 years ago
Edited by evaera 5 years ago

So the player is meant to give a response in a certain amount of time; but for some reason this isnt quite working the way Id expect it to.

"Chat" = nil

It waits for my response and everything (unless timeout) but Chat always comes up a nil. Help?

I understand its returning to fast but, how can I slow that down to get the correct chatted response?

function JARVIS:WaitForReply(Player)
    local Con
    local Chat = ""
    delay(12,function()
        Con:disconnect()
    end)
    Con = Player.Chatted:connect(function(Message)
        Chat = Message --> Message is fine
    end)
    Player.Chatted:wait()
    Con:disconnect()
    print(Chat) --> nil value
    return Chat
end
0
Chat = Message, you never define `C`, therefore, it is nil theCJarmy7 1293 — 5y
0
It was C = JARVIS:RemoveSlashE(Message) for anyone wanting to know. :) MessorAdmin 598 — 5y
0
Why is your chatted event inside a function? Bad practice. User#19524 175 — 5y
0
The reason its inside a function is because I dont need it often. Aka the reason: Con:disconnect() is there. MessorAdmin 598 — 5y
View all comments (4 more)
0
disconnect is not a thing, but Disconnect() is. User#19524 175 — 5y
0
disconnect IS a thing; go try it MessorAdmin 598 — 5y
0
^ `disconnect` is a "thing", but it was deprecated in favor of `Disconnect`. TheeDeathCaster 2368 — 5y
0
^^^ there we go MessorAdmin 598 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Right.. So I figured it out myself. I just wasnt very with it at that current time. I made a stupid mistake. (Actually multiple)

For anyone wanting the answer to this its below. :)

function JARVIS:WaitForReply(Player)
    local Con,Chat
    delay(12,function()
        Con:Disconnect()
        return nil
    end)
    Con = Player.Chatted:connect(function(Message)
        Chat = Message
    end)
    Player.Chatted:wait()
    wait()
    Con:Disconnect()
    return Chat
end
Ad
Log in to vote
-3
Answered by 5 years ago

You shouldn’t put events in functions:

loca chat = ''
local connection = player.Chatted:Connect(function(msg)
    chat = msg
    print(chat)
    connection:Disconnect()
end)
2
So.. where does it return then MessorAdmin 598 — 5y

Answer this question