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

I wanted to make it that whenever I say red on the chat, it prints red. So how do i fix this code? [closed]

Asked by 4 years ago
local Players = game:GetService("Players")
local play1Command = "/red"
local function onPlayerChatted(player, message)
    if message:sub(1, play1Command:len()):lower() == play1Command then
        print("u say red")
    end
end
0
Please next time, before you write a question try to find the answer on the web (the official article for Player.Chatted, for example) WoTrox 345 — 4y

Closed as Not Constructive by Dovydas1118, WoTrox, Optikk, and imKirda

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
WoTrox 345 Moderation Voter
4 years ago

You forgot to call your onPlayerChatted function

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        onPlayerChatted(plr, msg)
    end)
end)

Put this code somewhere in yours, and it should work

Let me know if I helped

Ad