Trying to make a chat script work

Im trying to make a script that every time a player said “/next” the npc says a message, right now im just testing it for message 1 but it isnt working, how do I get it fixed?

print(head)
local chatservice = game:GetService("Chat")
local prefix = script.Parent.Value
print(prefix)
local messages = {
	message1 = "The Industrial Revolution was a period of significant economic and social transformation that began in the late 18th century and lasted through the 19th century.",
	message2 = "It marked a transition from manual labor to machine-based manufacturing and the development of new technologies that led to increased productivity, efficiency, and economic growth.",
	message3 = "Environmental degradation: The increased use of fossil fuels and the expansion of industry led to significant pollution and environmental degradation, which had long-term consequences for the health of the planet and its ecosystems.",
	message4 = "Exploitation of workers: Workers in factories and mines were often subject to dangerous working conditions, long hours, and low wages. Children were also commonly employed in factories, which led to concerns about child labor and exploitation.",
	message5 = "Social inequality: The concentration of wealth and power in the hands of industrialists led to significant social inequality and class divisions, with workers often struggling to make ends meet while factory owners amassed great fortunes.",
	message6 = "Displacement of traditional ways of life: The growth of industry led to the displacement of traditional agricultural and artisanal economies, which had significant social and cultural consequences for rural communities."
}

print(messages.message1)

chatservice.Chatted:Connect(function(message)
	if message == prefix.Value.."next" then
		print('yay')
		chatservice:Chat(head, messages.message1)
	end
	end)

Instead of chatservice.chatted you should use player.chatted
Assuming this is a serverscript, you can do this:

print(head)
local chatservice = game:GetService("Chat")
local prefix = script.Parent.Value
print(prefix)
local messages = {
	message1 = "The Industrial Revolution was a period of significant economic and social transformation that began in the late 18th century and lasted through the 19th century.",
	message2 = "It marked a transition from manual labor to machine-based manufacturing and the development of new technologies that led to increased productivity, efficiency, and economic growth.",
	message3 = "Environmental degradation: The increased use of fossil fuels and the expansion of industry led to significant pollution and environmental degradation, which had long-term consequences for the health of the planet and its ecosystems.",
	message4 = "Exploitation of workers: Workers in factories and mines were often subject to dangerous working conditions, long hours, and low wages. Children were also commonly employed in factories, which led to concerns about child labor and exploitation.",
	message5 = "Social inequality: The concentration of wealth and power in the hands of industrialists led to significant social inequality and class divisions, with workers often struggling to make ends meet while factory owners amassed great fortunes.",
	message6 = "Displacement of traditional ways of life: The growth of industry led to the displacement of traditional agricultural and artisanal economies, which had significant social and cultural consequences for rural communities."
}

print(messages.message1)

game.Players.PlayerAdded:Connect(function(player)
         player.Chatted:Connect(function(message)
	if message == prefix.."next" then
		print('yay')
		chatservice:Chat(head, messages.message1)
	end
	end)
end)

Also, if you get an error about a string and nil, change line 20 to if msg == prefix.."next" then

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