-- Function to handle chat messages
local function onChatted(player, message)
if message:lower() == "!admin" then
script.Parent.Enabled = true
end
end
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.Chatted:Connect(function(message)
onChatted(player, message)
end)
I want to put it in StarterGui, it works in workspace but just not starter gui? No error happens.
I’ve tried using the code you provided and it didn’t work for me both in Workspace and StarterGui. I guess that is related to the outdated Chatted event itself.
Here is the modern version of the script that uses TextChatService:
--!strict
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
TextChatService.MessageReceived:Connect(function(textChatMessage)
if textChatMessage.TextSource.UserId ~= player.UserId then
return
end
local message = textChatMessage.Text
if message:lower() == "!admin" then
script.Parent.Enabled = true
end
end)