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

Players userId won't be added to a table?

Asked by 3 years ago

I'm trying to make an admin panel that bans a player when I enter the player name, reason and then press the ban button (gui button) then the players userId should be inserted into a table.

I'm trying to send a string value of the players name to the server script to ban them using a for i, v loop.

Local script code to detect when the button is pressed:

local Main = script.Parent.Main 

local WhoFrame = Main.WhoFrame
local PlrName = game.ReplicatedStorage.PlrName

Main.WhoFrame.BanButton.MouseButton1Click:Connect(function()
    PlrName.Value = WhoFrame.PlayerList.Text
    game.ReplicatedStorage.BanPlayer:FireServer()
    end)

PlrName is the string and player list is where I type the players name into.

Server script 1:

local GetList = game.ReplicatedStorage.GetList
local BanPlr = game.ReplicatedStorage.BanPlayer
local PlrName = game.ReplicatedStorage.PlrName




local BanList = {}

BanPlr.OnServerEvent:Connect(function(player)
for i, v in pairs(game.Players:GetPlayers()) do
    if PlrName == v then
            table.insert(BanList, player.UserId)
            print("Player is in ban list")
    end
end

GetList.OnInvoke = function(Player)
    for i, v in pairs(BanList) do
        if v == Player.UserId then
            print("Player Is In The Ban List")
            return true
        else
            print("Player is not in the ban list")
            return false
        end
        end
    end
    end)



Server script 2 (detects when the player logs back on)

local GetList = game.ReplicatedStorage.GetList

game.Players.PlayerAdded:Connect(function(player)
    local IsPlayerBanned = GetList:Invoke(player)
    if IsPlayerBanned == true then
        player:Kick("You are banned")
    end
end)

Thanks for reading!

(Sorry if the code is confusing I followed a manual tutorial and tried to make it automatic)

0
You never actually sent any arguments through :FireServer() :| Ziffixture 6913 — 3y
0
What kind of arguments should I send through FireServer() would things like the player work? TheStarRblx 27 — 3y

1 answer

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

OnServerEvent recieves one parameter by default which is the player that ran the event. In your server script 1 you add the player who ran it into the table. You would have to do something like this:

BanPlr.OnServerEvent:Connect(function(_,player)
for i, v in pairs(game.Players:GetPlayers()) do
    if PlrName == v then
            table.insert(BanList, player.UserId)
            print("Player is in ban list")
    end
end

Also in your local script the 'MouseButton1Click' seems to never work- at least for me. Try 'MouseButton1Down'.

Main.WhoFrame.BanButton.MouseButton1Down:Connect(function()
    PlrName.Value = WhoFrame.PlayerList.Text
    game.ReplicatedStorage.BanPlayer:FireServer()
    end)

0
Thanks for the answer, but it still won't work, I added a player:Kick() to the end and it wont kick the player? TheStarRblx 27 — 3y
0
Found another issue I'll just edit my answer CrunchChaotic 139 — 3y
Ad

Answer this question