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

How to make a hint admin command?

Asked by
ANE_bot 17
4 years ago

i want to know how to make a hint appear when someone says something. for example:

archmantella13: $hint Hello

and then a hint saying archmantella13: Hello appears. Here is what i have:

if string.sub(string.lower(msg),1,2) == "h/" then
text(speaker.Name .. ": " .. string.sub(msg,3),2,"Hint",game.Workspace)
end
0
Your current code is pretty much perfect! Just make sure that the user prefixes their message with "$hint" and then make the hint thebayou 441 — 4y
0
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 Shawnyg 4330 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

All you'd need to do is change "h/" to whatever you want to do for it to work.

0
thx for making me learn the chat system, i was able to answer this guy's question because of it! throwawayaccount2001 102 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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} -- put the id of people you want to be admin
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)
-- Don't change position
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
                -- Create the hint
                -- First filter the hint's message
                local newMessage = filterMessage(speakerName..": "..(string.sub(message, 7, -1)), game.Players:FindFirstChild(speakerName))
                -- Then send it out
                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")
            -- You can put code here that does stuff like warn the player they are not admin
            return true
        else
            return false
        end
    end
    ChatService:RegisterProcessCommandsFunction("hint", hintCommand)
end

return Run

Answer this question