.Chatted function, not working?

Hello everyone!
so i was making a bot commands thingy for my model. I finished the module but there’s a problem in Chatted function. it supposed to print the message that the user said but it didn’t print any as you can see in results. I used print() to test if the function was runned because there was several script that supposed to happen but didn’t happen.

Script

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		print(message)
    end)
end)
Full Script
local RoBot = require(8757425865)
local Bots = require(game.ServerScriptService.BotsModule)
RoBot:Create({
	{'Bot_Name'},					-- Bot Name
	{Vector3.new(255, 247, 0)}, 	-- Chat Name Color
	{Color3.new(1, 1, 1)}, 			-- Chat Text Color
})
RoBot:Var('Bot_Name','Prefix',{'?';'!'})

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		print(message)
		if typeof(Bots['Bot_Name']['Variables']['Prefix']) == 'table' then
			for _,FindPrefix in pairs(Bots['Bot_Name']['Variables']['Prefix']) do
				if message == FindPrefix..'ping' then
					RoBot:Say('Bot_Name','pong!')
					break -- stops from finding if the prefix
				end
			end
		elseif typeof(Bots['Bot_Name']['Variables']['Prefix']) == 'string' then
			if message == Bots['Bot_Name']['Variables']['Prefix']..'ping' then
				RoBot:Say('Bot_Name','pong!')
			end
		end
	end)
end)

Results

image

I’ve searched:

[Player.chatted function not working - #20 by httpDerpyy] - there we’re no similar name as the function parameter
[Player.Chatted not working - #5 by NinjaFurfante07] - doesn’t match :frowning:
[player.Chatted doesn't work in Studio] - doesn’t match just bug report :frowning:

2 Likes
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == ("Your message") then
         print("Succes")
        end
    end)
end)
1 Like

well that’s supposed to help if that’s my problem but no. i add print in .Chatted function to test if the function is being runned but unfortunately not. i put the full script there so you would know.

1 Like

i fixed it by changing it to local RoBot = require(script.Parent.MainModule) from local RoBot = require(8757425865). Does anyone know how to fix this?"

i fixed it by changing it to local RoBot = require(script.Parent.MainModule) from local RoBot = require(8757425865). Does anyone know how to fix this?

How was that related to the chatted function? Was it throwing an error at that line?

What do you need to fix?

well i was expecting that it’s causing error because of the require thing, and i need help on fixing this because i want to set it to this require(8757425865) instead of this require(script.Parent.MainModule)

I think the problem might be PlayerAdded function not firing once you join the game. That’s why it never printed the message you chatted. (The playeradded connection was added AFTER you join the game, I think that’s why). Try this attempt:

local function PlayerAdded(player)
    player.Chatted:Connect(function(message)
        print(message)
    end)
end

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(PlayerAdded)

-- This extra piece of code goes through everyone in the server to make sure
-- the rest of the player in the server that haven't ran PlayerAdded  
-- runs it with the parameter as their player. (Sorry bad wording)
for _, player in ipairs(Players:GetPlayers()) do
    PlayerAdded(player)
end

Do you own the module you’re requiring when doing it by id? You need to own it if it’s not public and the module’s name has to be “MainModule”

well it’s still did the same, and in this

for _, player in ipairs(Players:GetPlayers()) do
    PlayerAdded(player)
end

it will just repeat on 1 person who joined first…

i own it, the require was successful but it makes the rest of the script unsuccessful

Can you please show use the whole code?

it’s alright because I’m ok with an path instead of asset id require, thanks

From where you are calling the event and etc? Is it from a local script or a server script?

Server Script, Obviously and i really appreciate helping or participating but i fixed my problem so thanks.

1 Like

Oh sorry didn’t know that because you said this in the message you marked as the solution.

1 Like