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.
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)
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == ("Your message") then
print("Succes")
end
end)
end)
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.
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?"
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