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

Script doesn't work or I'm using tables wrongly?

Asked by 5 years ago

So, I've trying to make an anti-backdoor script so that it will check every remote in ReplicatedStorage to see whether it's name is on the AllowedRemotes table, but it deletes every remote inside of ReplicatedStorage. Any help?

local RStorage = game:GetService("ReplicatedStorage")
local AllowedRemotes = {
    "DefaultServerSoundEvent",
    "AddCharacterLoadedEvent",
    "RemoveCharacterEvent",
    "SoundDispatcher",
    "OnNewMessage",
    "OnMessageDoneFiltering",
    "OnNewSystemMessage",
    "OnChannelJoined",
    "OnChannelLeft",
    "OnMuted",
    "OnUnmuted",
    "OnMainChannelSet",
    "ChannelNameColorUpdated",
    "SayMessageRequest",
    "SetBlockedUserIdsRequest"
}

while wait() do
    for _, v in pairs(RStorage:GetDescendants()) do
        if v:IsA('RemoteEvent') then
            if AllowedRemotes[v.Name] then
                -- do nothing
            else
                v:Destroy()
            end
        end
    end
end
0
Filtering enabled blocks most client changes from replicating to the server. There is no need to do and "anti exploit" checks if you validate the remove event requests correctly. User#5423 17 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

A table is built out of indexes… each index is a value. in your table, the value is a string containing the name of the remote that is allowed, but the index is still a number… there are 2 options, either you use custom keys for your table, or you go through the table to compare the value in it to the name

OPTION 1

local table = {
            key1 = "string 1",
            key2 = 2,
            key3 = 10
    }


print(table["key1"])        -- prints: string 1
print(table[0])         -- also print: string 1

OPTION 2

local table = {
            "string1",
            2,
            10
    }


for index,value in pairs in ipairs(table) do
    if value == "string 1" then
        print(table[index])         -- will print: string 1, is the same as printing value
    end
end

to end this message, your updated script can be found below:

local RStorage = game:GetService("ReplicatedStorage")
local Found = false

local AllowedRemotes = {
    "RemoteEvent",
    "RemoteEvent1",
    "RemoteEvent2",
    "RemoteEvent3",
    "RemoteEvent4"
}

while wait() do
    for _,v in pairs(RStorage:GetDescendants()) do
        if v:IsA('RemoteEvent') then
            for index,value in ipairs(AllowedRemotes) do
                if v.Name == value then
                    Found = true
                end
            end
            if Found == true then
                Found = false
            else
                v:Destroy()
                Found = false
            end
        end
    end
end
1
Please check your OPTION 1 code. line 8 should be table["key1"] or table.key1 and line 9 will not work at all. User#5423 17 — 5y
0
Works, thanks! Bean_dinosaur 42 — 5y
Ad

Answer this question