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
7 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?

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

2 answers

Log in to vote
1
Answered by 7 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:

01local adminList = {"Plieax", "Bob", "Joe"} -- names are examples
02 
03function checkIfPlayerIsAdmin(player) -- will equal false if the player is not an admin
04    for i,v in pairs(adminList) do
05        if v == player.Name then
06            return true
07        end
08    end
09    return false
10end
11 
12game.Players.PlayerAdded:connect(function(player)
13    if checkIfPlayerIsAdmin(player) then
14 
15        -- Put your code in here
16 
17    end
18end)
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 7 years ago
1game.Players.PlayerAdded:Connect(function(plr)
2    if plr.Name == "Plieax" then
3        plr.PlayerGui:WaitForChild "OpenAdmin".Enabled = true
4    end
5end)
0
you didnt change anything Plieax 66 — 7y
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 — 7y

Answer this question