Does anyone know why this script isnt working?

Does anyone know why this isn’t working?

-- 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.
image

Since your screengui is disabled before the message runs, the local script can’t even run because its parent is disabled.

That would be like typing “script.Enabled = true” in a disabled script.

1 Like

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)
2 Likes

That worked, thank you, for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.