Basic Admin Sticky Message

Hello! Recently, I wanted to make a sticky message command, when Player A types the command “sticky” then there will have a hint message but it wouldn’t disappear until we click it. (Note, I want it as a plugin (BAE))

Player A :sticky Greetings, welcome to the Cafe!
System Shows hint message but never disappears until we click it

I think it will work because Frappe is using them too.

If other admins wnat to replace them they just need to say :clr (system included)

3 Likes

You seem to be new to the forum. I recommend you switch the category of this post. Development Discussion is only used for discussion of Roblox Development. You can most likely find your answer in the category #help-and-feedback:scripting-support, so please switch the category to that by editing your post.

1 Like

thank you for notice me abt that!

You can detect when a player has chatted by using the Player.Chatted event. From there, you can use the string.sub function to see if the player’s message contains the “:sticky” command you’re looking for. Finally, you can again use the string.sub function to get the rest of the player’s message, and add that to whatever Gui you’re using to display the text.

Here’s code you can use if you want to; however, I would encourage you to try to write your own code before you look at mine.

This can go in a Script inside ServerScriptService.

Code
local Players = game:GetService("Players")

-- Triggers when player joins game
Players.PlayerAdded:Connect(function(player)
	
	-- Triggers when player sends a chat message
	player.Chatted:Connect(function(message)
		
		-- Checks if first 7 letters of message = ":sticky"
		if string.lower(string.sub(message, 1, 7)) == ":sticky" then
			
			-- Loops through message, starting at the 9th letter, as the first 7 should be ":sticky" and the eigth should be a space
			for i = 9, #message do
				
				-- Prints out the letter. Replace this with whatever you want to do with each lettter.
				print(string.sub(message, i, i))
			end
		end
	end)
end)

Are you write as a basic admin essentials plugin?

You mean the code I provided in that post? No, it isn’t a plugin. It’s just a script that checks if a player says “:sticky”, although with some revision you could get it to detect many more commands/messages.

Hi, I’ve been customizing BAE for a long while (even do comms for it) and a :sticky command requires editing the mainmodule and cannot be done with just a plugin.

1 Like

Okay, well I created a script that should do for a base/code to examine and learn. It is completely untested so it may not work, and it’s not a plugin for BAE but it can be extended for new commands, a clearing sticky system, and it’s cross server.
Since it sounds like you don’t really know much about coding, I tried to explain everything that happens.

local Prefix = ":"

function Sticky(Message)
    -- do sticky code, remember to filter it. https://create.roblox.com/docs/ui/text-filtering
end

local Commands = { -- should probably be a module, but I don't want to add too many things to add to seperate scripts
    ["sticky"] = function(Player, Message, Splits)
        local Valid = nil -- set valid to nil/false
        for i,GamePlayers in pairs(game.Players:GetPlayers()) do -- loop through all players
            if not Splits[2] then break end -- if they didn't add a player argument to it, just instantly break so it returns
            if string.sub(GamePlayers.Name:lower(), 1, #Splits[2]) == Splits[2] then -- check if the players name lowered and subbed to the length of splits[2] is equal to splits[2]
                Valid = GamePlayers -- set valid player
            end
        end
            
        if not Valid then
            -- invalid player argument/player not found, probably do some ui stuff to tell the player that
            return
        end
        
        if not Splits[3] then
            -- no sticky message, tell the player that
            return
        end

        local StickyString = Splits[3]

        if Splits[3]:lower() == "true" then -- check for a hidden third argument, and that it is "true"
            if not Splits[4] then
                -- no sticky message, tell the player that
                return
            end
            StickyString = Splits[4]
            game:GetService("MessagingService"):PublishAsync("sticky", StickyString) -- publish to other servers for crossserver
        end
        
        Sticky(StickyString)
    end,
    ["clr"] = function(Player, Message, Splits)
        if Splits[2] == "sticky" then
            -- do thing to clear stickys, since I do not know how you are doing the uis I can't help here
        end
    end
}
game:GetService("Players").PlayerAdded:Connect(function(Player) -- detect player join
    local ChatConnection = Player.Chatted:Connect(function(Message) -- detect message sent
        local Splits = Message:split(" ") -- split the messages segments into a table, ex: {"hello", "world!"}
        
        for Name,CommandFunction in pairs(Commands) do -- loop through all commands
            if Splits[1] == `{Prefix}{Name}` then -- check if the message split is equal to ":".. `{command}`
                CommandFunction(Player, Message, Splits) -- run command
            end
        end
    end)
end)

-- cross server
game:GetService("MessagingService"):SubscribeAsync("sticky", function(data) -- connect to the other servers, think of it like a global RemoteEvent
    Sticky(data)
end)

If you understand the code and what each thing does, you can probably apply it to BAE yourself. Also, don’t forget you NEED to filter the text.

1 Like