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

Global Announcement System not responding?

Asked by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

I’ve written a program using the MessagingService. I just recently discovered this Service so I wrote this souly on the purpose of messing around with it. The function of the program is to allow the User to write !announce within the ROBLOX chat, followed by whatever the message given. It will then use that and create a SystemMessage via ChatMakeSystemMessage. The program hasn’t given and output or shown any present syntax issues. I’m not sure what’s wrong, but I have a hunch it may be an issue with comparing the conjoined string and chat:sub() result on line 16?

 --// Script under ServerScriptService 
local messagingService, subscription = game:GetService("MessagingService"), "GlobalAnnounce" 
local coreGui = game:GetService("StarterGui") 
local playerService = game:GetService("Players")

local userList = {
    [74087102] = "Feahren" 
};

local prefix, call = [[!]], [[announce ]]

playerService.PlayerAdded:Connect(function(player) 
    player.Chatted:Connect(function(chat, recipient) 
        if not (userList[player.UserId]) or recipient then return end 
        if (chat:sub(#prefix, #call):lower() == string.lower(prefix..call)) then 
            local token = chat:FilterStringForBroadcast(chat:sub((#prefix+#call)), player)
            messagingService:PublishAsync(subscription, token) 
        end 
    end) 
end)

messagingService:SubscribeAsync(subscription, function(received)
    local data, tStamp = unpack(received) 
    coreGui:SetCore("ChatMakeSystemMessage", { 
        Text = "[ANNOUNCEMENT]: "..data, 
        Color = Color3.fromRGB(255,255,255), 
        Font = Enum.Font.SourceSansBold
    }); 
end) 

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Question

Global Announcement System not responding?

What's Wrong

I'm honestly not sure from looking at the code but I suspect it is a problem with the space (" ") after announce in the variable call. (I printed every byte in the string and this DOES appear to be this issue??)

Solution

Add 1 to the length of call; chat:sub(#prefix, #call + 1):lower() == string.lower(prefix..call)

Also, since concatenation returns a string you can use (prefix .. call):lower()

Extra

I suggest you instead use a different method to handle how the admin works (why not just use a simple if match in this case??)

Dirty code I wrote to find the problem; notice the 32 on b_1

        local a, b = chat:sub(#prefix, #call):lower(), string.lower(prefix .. call)

        local a_1 = ""
        for v in a:gmatch(".") do
            a_1 = a_1 .. "," .. v:byte()
        end

        local b_1 = ""
        for v in b:gmatch(".") do
            b_1 = b_1 .. "," .. v:byte()
        end
Ad

Answer this question