How do I make a chat function?

So, I’m a new scripter, and I’ve figured out how functions and variables work, (In which i feel like that’s a big step!) And I’m trying to create a script where if a player says yes or no, a part in the workspace turns green (yes) or red (no). The way I’m approaching this is by calling functions. I have the first two functions down on this example, and I’m not sure how to make the chat part:

function yes()
	workspace["Fiddle Part"].BrickColor = BrickColor.new("Lime green")

end
	function no()
		workspace["Fiddle Part"].BrickColor = BrickColor.new("Really red")
	
	end

I would really appreciate if someone could help me, thank you.

Do you want this function to run for only the local player, or the every player? Also, move this to #help-and-feedback #help-and-feedback:scripting-support, as this is a scripting question.

Open Here if you want the changes to be shown to everyone in the server
local players = game:GetService("Players")

function yes()
	workspace["Fiddle Part"].BrickColor = BrickColor.new("Lime green")

end
function no()
	workspace["Fiddle Part"].BrickColor = BrickColor.new("Really red")

end

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:lower() == "yes" then
			yes()
		elseif message:lower() == "no" then
			no()
		end
	end)
end)

Put the script under ServerScriptService [if you want these changes to be shown to everyone in the server]

Open Here if you want the changes to be shown to the local player only

if you want the changes to be shown only to the player , then use -

local players = game:GetService("Players")
local player = players.LocalPlayer

	function yes()
		workspace["Fiddle Part"].BrickColor = BrickColor.new("Lime green")

	end
function no()
	workspace["Fiddle Part"].BrickColor = BrickColor.new("Really red")

end

player.Chatted:Connect(function(message)
	if message:lower() == "yes" then
		yes()
	elseif message:lower() == "no" then
		no()
	end
end)

make sure this is a local script

by the way, we’re using lower() so even if the player says ‘NO’,‘YES’,‘nO’,‘YEs’,etc… it’ll apply for it.

If you want it to only change for a specific player (the one who said yes/no), do

game.Players.LocalPlayer.Chatted:Connect(function(Message)
    if string.lower(Message) == "yes" then
       print("Yes")
    elseif string.lower(Message) == "no" then
       print("No")
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.