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

Wait for user chatted response? [solved]

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

8 comments

0

Chat = Message, you never define C, therefore, it is nil

0

It was C = JARVIS:RemoveSlashE(Message) for anyone wanting to know. :)

0

Why is your chatted event inside a function? Bad practice.

0

The reason its inside a function is because I dont need it often. Aka the reason: Con:disconnect() is there.

0

disconnect is not a thing, but Disconnect() is.

0

disconnect IS a thing; go try it

0

^ disconnect is a "thing", but it was deprecated in favor of Disconnect.

0

^^^ there we go

2 answers

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

You shouldn’t put events in functions:

loca chat = ''
local connection = player.Chatted:Connect(function(msg)
    chat = msg
    print(chat)
    connection:Disconnect()
end)

1 comment

2

So.. where does it return then

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