Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the chat reply on chatted message?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

I wonder if there is a way to make the chat reply back once the certain message is said


player = game.Players.LocalPlayer.Character function chat(text) game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ Text = text; Color = Color3.new(255,255,255); StrokeColor = Color3.new(0,0,0); Font = Enum.Font.SourceSansItalic }) end for i =1,3 do if i == 1 then chat("Welcome") elseif i == 2 then chat(player.Name) function onChatted(msg, recipient, speaker) local source = string.lower(speaker.Name) msg = string.lower(msg) if i == 3 then if (msg == "no") then -- Message said for the reply chat("rude") -- The reply end end end end end

No errors in output

1 answer

Log in to vote
3
Answered by 8 years ago

You haven't added the player.Chatted connection line to call the function, also to do this player would need to be the actual player, not the character. Add

player.Chatted:connect(function(msg, recipient, speaker)

instead of

function onChatted(msg, recipient, speaker)

Once you've changed it, it should be like this:

player = game.Players.LocalPlayer -- removed .Character
function chat(text)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
        Text = text;
        Color = Color3.new(255,255,255);
        StrokeColor = Color3.new(0,0,0);
        Font = Enum.Font.SourceSansItalic
    })
end

for i =1,3 do
    if i == 1 then
        chat("Welcome")
    elseif i == 2 then
        chat(player.Name)
        player.Chatted:connect(function(msg, recipient, speaker) -- Made the connection line
            local source = string.lower(speaker.Name) 
            msg = string.lower(msg) 
            if i == 3 then
                if (msg == "no") then -- Message said for the reply
                    chat("rude") -- The reply
                end
            end
        end)
    end
end

I removed the unnecessary for loop and just make it simpler. Here's my finished code:

player = game.Players.LocalPlayer -- removed .Character

function chat(text)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
        Text = text;
        Color = Color3.new(255,255,255);
        StrokeColor = Color3.new(0,0,0);
        Font = Enum.Font.SourceSansItalic
    })
end

chat("Welcome") -- Welcome them
wait(3) -- Wait for it to be removed
chat(player.Name) -- Say their name
wait(3) -- Wait for it to be removed
player.Chatted:connect(function(msg) -- Made the connection line
    msg = string.lower(msg) -- convert to lower case
    if msg == "no" then -- Message said for the reply
        chat("rude") -- The reply
    end
end)
Ad

Answer this question