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

Why is this if statement triggering and how do I fix it?

Asked by
Plieax 66
6 years ago

Ok so I need the gui to only be activated if the players name is Plieax but when I play my game on another account the if statement still runs allowing the non-admin player admin abilities. How do I fix this?

game.Players.PlayerAdded:connect (function(plr)
    if plr.Name == "Plieax" or "" or "" then -- Put Names Of Admins Between The ""s -- 
        plr.PlayerGui:WaitForChild "OpenAdmin".Enabled = true
    end 
end)
0
if I helped you out please accept my answer. Otherwise comment how I can help you better User#21908 42 — 5y

2 answers

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

It would help if you used a table to save the admins names and used a function to check and see if they are a admin. Here is an example:

local adminList = {"Plieax", "Bob", "Joe"} -- names are examples

function checkIfPlayerIsAdmin(player) -- will equal false if the player is not an admin
    for i,v in pairs(adminList) do
        if v == player.Name then
            return true
        end
    end
    return false
end

game.Players.PlayerAdded:connect(function(player)
    if checkIfPlayerIsAdmin(player) then

        -- Put your code in here

    end
end)
0
You messed up on line 7, just because the first name out of the table and the player don't match doesn't mean the 2nd name and the p^layer won't match! User#20388 0 — 6y
0
remove the 'else return false' and on the end of the for i,v in pairs add return false, if it didn't return yet, it would return false, if it did, it would return true User#20388 0 — 6y
0
You're right I messed up. This is a script I wrote a while back and I forgot the order it went in let me fix it. User#21908 42 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "Plieax" then
        plr.PlayerGui:WaitForChild "OpenAdmin".Enabled = true
    end 
end)

0
you didnt change anything Plieax 66 — 6y
0
he's actually right though, no one is ever going to have no name, this does exactly what you want it to do 4PlayerGamingRoblox 38 — 6y

Answer this question