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

Admin panel not working with a for loop going through a table?

Asked by 4 years ago

So i'm trying to make an admin panel and I have all of the localscript done and im handling the rest on the server and I have this admin table that shows all the names of the admins but when I go to run the script when I fire the RemoteEvent it shows "Working" 4 times in the console yet the button doesn't do anything and it wont print errors? Here is my code:

Admins = {"Nob", "Elypanft", "GamerPlayesRoblox_YT", "Player1"}
remote = game.ReplicatedStorage.Admin

game.Players.PlayerAdded:Connect(function(player)
    for _, v in pairs(Admins) do
        if player.Name == v then
            game.Players[player.Name].PlayerGui:WaitForChild("Admin").Enabled = true
        end
    end
end)


function kick(a,b)
    game.Players[a]:Kick(b)
end

function freeze(a)
    game.Players[a].Character.Humanoid.WalkSpeed = 0
    game.Players[a].Character.Humanoid.JumpPower = 0
end

function unfreeze(a)
    game.Players[a].Character.Humanoid.WalkSpeed = 16
    game.Players[a].Character.Humanoid.JumpPower = 50
end

function admin(a)
    Admins.Add(a)
end

function teleport(a, b)
    local targetplayer = game.Players[b].Character.HumanoidRootPart
    game.Players[a].Character.HumanoidRootPart.CFrame = CFrame.new(targetplayer.Position.X, targetplayer.Position.Y, targetplayer.Position.Z)
end

remote.OnServerEvent:Connect(function(player, cmd, target, reason)
    for _, v in pairs(Admins) do -- it loops 4 times here when i want it to loop once
        print("Working")
        if player.Name == Admins then
            if cmd == "Kick" then
                kick(target, reason)
            end
            if cmd == "Freeze" then
                freeze(target)
            end
            if cmd == "Unfreeze" then
                unfreeze(target)
            end
            if cmd == "Admin" then
                admin(target)
            end

            if cmd == "TeleportTo" then
                teleport(player, target)
            end
        end

        if not player.Name == Admins then -- checks if a nonadmin fired the remote
            game.Players[player]:Kick("Exploiting Admin Panel")
        end
    end
end)
0
Um. I thought you can only send two things through remote events...... Sending more makes the serverside code break. Also if you are trying to make an exploit... You can't use remote events unless they already existed in the game. Also you kick doesnt have a target. Please show your full code including the server side parts voidofdeathfire 148 — 4y
0
I'm making my admin panel exploit proof and this is all the serverside stuff muffin1234 0 — 4y
0
You must be shit at code because my kick works just fine now I fixed it its just i put admins instead of v muffin1234 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Instead of "if player.Name == Admins then", put "if player.Name == v then", as Admins, is the name of the table, and v is the value stored in the table, being one of the admins! :)

Hope this helped, let me know if it fixed your problem, Thanks!

Ad

Answer this question