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

A key part of my code isn't firing, as if it wasn't even there. Could anybody explain this?

Asked by 5 years ago

I'm creating an admin panel and in that admin panel will be a feature to see all whispers and team chats. For now, I just have it print the messages in the on the client's chat (It's a local script).

The problem I'm having is that this code isn't firing, as if the code wasn't even there:

local CheckMessageHidden = GetMessage.OnClientEvent:Connect(function(Packet, Channel)
    if Channel == "All" or (Channel == "Team" and Players[Packet.FromSpeaker].Team == Player.Team) then
        TypeOfMessage = "Visible"
    end
    if TypeOfMessage == "nil" then
        if (Message:lower():sub(1, 2) == "/t" or Channel == "Team") and Players[Packet.FromSpeaker].Team ~= LocalPlayer.Team then
            TypeOfMessage = "Team"
        elseif Channel:lower():sub(1, 2) == "to" or Message:lower():sub(1, 2) == "/w" then
            TypeOfMessage = "Whisper"
        elseif Message:lower():sub(1, 2) == "/e" then
            TypeOfMessage = "Emote"
        end
    end
    TypeOfMessage = "Other"
end)

I'd really appreciate it if somebody could explain what is happening here.

Also, here is the entire code:

MessageProperties = {
    Color = Color3.fromRGB(0, 153, 255); 
    Font = Enum.Font.SourceSansBold;
    TextSize = 18;
}

local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
local GetMessage = game:GetService("ReplicatedStorage"):WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("OnMessageDoneFiltering")

local function onChatted(Player, Message)
    Message = Message:gsub("[\n\r]", ""):gsub("\t", " "):gsub("[ ]+", " ")
    local TypeOfMessage = "nil"
    local CheckMessageHidden = GetMessage.OnClientEvent:Connect(function(Packet, Channel)
        if Channel == "All" or (Channel == "Team" and Players[Packet.FromSpeaker].Team == Player.Team) then
            TypeOfMessage = "Visible"
        end
        if TypeOfMessage == "nil" then
            if (Message:lower():sub(1, 2) == "/t" or Channel == "Team") and Players[Packet.FromSpeaker].Team ~= LocalPlayer.Team then
                TypeOfMessage = "Team"
            elseif Channel:lower():sub(1, 2) == "to" or Message:lower():sub(1, 2) == "/w" then
                TypeOfMessage = "Whisper"
            elseif Message:lower():sub(1, 2) == "/e" then
                TypeOfMessage = "Emote"
            end
        end
        TypeOfMessage = "Other"
    end)

    CheckMessageHidden:Disconnect()

    if TypeOfMessage ~= "nil" then
        if TypeOfMessage == "Team" then
            MessageProperties.Text = "{Team} ["..Player.Name.."]: "..(Message:lower():sub(1, 2) == "/t" and Message:sub(3) or Message)
            StarterGui:SetCore("ChatMakeSystemMessage", MessageProperties)
        elseif TypeOfMessage == "Whisper" then
            local Whispering = Message:split(" ")[2]
            MessageProperties.Text = "{To"..Whispering.."} ["..Player.Name.."]: "..(Message:lower():sub(1, 2) == "/w" and Message:sub(4 + #Whispering) or Message)
            StarterGui:SetCore("ChatMakeSystemMessage", MessageProperties)
        elseif TypeOfMessage == "Emote" then
            MessageProperties.Text = "{Emote} ["..Player.Name.."]: "..Message:sub(3)
            StarterGui:SetCore("ChatMakeSystemMessage", MessageProperties)
        elseif TypeOfMessage == "Other" then
            MessageProperties.Text = "{Other} ["..Player.Name.."]: "..Message:sub(3)
            StarterGui:SetCore("ChatMakeSystemMessage", MessageProperties)
        end
    end
end

for i, v in pairs(Players:GetPlayers()) do
    v.Chatted:Connect(function(Message)
        onChatted(v, Message)
    end)
end

Players.PlayerAdded:Connect(function(v)
    v.Chatted:Connect(function(Message)
        onChatted(v, Message)
    end)
end)
0
Your event isn't fired anywhere? Abandion 118 — 5y

Answer this question