Put the following code in a ModuleScript inside of a Folder called "ChatModules" parented to Chat (do all of this pre-runtime). Inside of ChatModules, also have a BoolValue called "InsertDefaulModules" set to true.
local idsOfAdmins = {128498925, -1, 0, game.CreatorId}
local currentHint
local hintDisplayed = false
local gui = Instance.new("ScreenGui")
gui.Name = "HintGui"
local hint = Instance.new("TextLabel")
hint.Name = "Hint"
hint.Visible = false
hint.Size = UDim2.new(1,0,0,25)
hint.BackgroundColor3 = Color3.new()
hint.BorderSizePixel = 0
hint.Font = Enum.Font.Legacy
hint.TextColor3 = Color3.new(1, 1, 1)
hint.TextScaled = true
local newGui
local newHint
local TextService = game:GetService("TextService")
local function Run(ChatService)
local function filterMessage(message, speaker)
local textResult = TextService:FilterStringAsync(message, speaker.UserId, Enum.TextFilterContext.PublicChat)
local newMessage = textResult:GetNonChatStringForBroadcastAsync()
return newMessage
end
local function hintCommand(speakerName, message, channelName)
local isAdmin = true
for i, v in ipairs(idsOfAdmins) do
if game.Players[speakerName].UserId == v then
isAdmin = true
break
end
end
if isAdmin and string.lower(string.sub(message, 1, 5)) == "$hint" then
if not hintDisplayed then
local newMessage = filterMessage(speakerName..": "..(string.sub(message, 7, -1)), game.Players:FindFirstChild(speakerName))
newHint = hint:Clone()
newHint.Text = newMessage
newHint.Visible = true
newGui = gui:Clone()
for _, player in ipairs(game.Players:GetPlayers()) do
local playerHint = newHint:Clone()
local playerGui = newGui:Clone()
playerGui.Parent = player.PlayerGui
playerHint.Parent = playerGui
end
game.Players.PlayerAdded:Connect(function(player)
player:WaitForChild("PlayerGui")
local playerHint = newHint:Clone()
local playerGui = newGui:Clone()
playerGui.Parent = player.PlayerGui
playerHint.Parent = playerGui
end)
hintDisplayed = true
else
local newMessage = filterMessage(speakerName..": "..(string.sub(message, 7, -1)), game.Players:FindFirstChild(speakerName))
newHint.Text = newMessage
for _, player in ipairs(game.Players:GetPlayers()) do
player.PlayerGui.HintGui.Hint:Destroy()
local playerHint = newHint:Clone()
playerHint.Parent = player.PlayerGui.HintGui
end
end
return true
elseif not isAdmin and string.lower(string.sub(message, 1, 5)) == "$hint" then
print("Not admin")
return true
else
return false
end
end
ChatService:RegisterProcessCommandsFunction("hint", hintCommand)
end
return Run
2 comments
Your current code is pretty much perfect! Just make sure that the user prefixes their message with "$hint" and then make the hint
We'd need to see what the text function is. Assuming this is from an admin script from Free Models, just change "h/" to "$hint" and 1,2 to 1,5 and msg,3 to msg,6