Talking TV Based Off User Input

This is a talking TV based off of user chatting!

It does the job, it works. I just want to know what you guys would’ve done differently, as I am somewhat new to scripting.

And is this considerably decent code?

game.Players.PlayerAdded:Connect(function(player)
	local screen = game.Workspace.Screen.screenGUI.TextBox
	
	local greetingDictionary = {
		'hello', 'hi', 'hey', 'yo', 'sup'
	}
	local responseDictionary = {'Hey there!', 'How are you?', 'What are you doing?'}
	
	local userResponse1 = {'im good', 'good'}
	
	local userResponse2 = {'nothing'}
	
	local tvResponse1 = {'That is good to hear. I am a TV, I dont have feelings.'}
	
	player.Chatted:Connect(function(msg)
		for i, v in pairs(greetingDictionary) do
			if msg == v then
				local chosenResponse = math.random(1, #responseDictionary)
				if chosenResponse == 1 then
					screen.Text = responseDictionary[chosenResponse]
				elseif chosenResponse == 2 then
					screen.Text = responseDictionary[chosenResponse]
				elseif chosenResponse == 3 then
					screen.Text = responseDictionary[chosenResponse]
				end
			end
		end
		
		for i, v in pairs(userResponse1) do
			if msg == v then
				screen.Text = tvResponse1[1]
			end
		end

		if msg == "nothing" then
			screen.Text = 'Oh. I am just talking to ROBLOXIANS.'
		end
	end)
end)

Your code looks good for someone who is new to scripting. However, I would recommend using string.lower when comparing the players message to your user responses.

You can learn more about string.lower and other string API here: https://developer.roblox.com/en-us/api-reference/lua-docs/string

1 Like

I appreciate your help!
This took me about 2 minutes to figure out how to use string.lower. I see its use, thank you!