Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script doesnt set anyone with the name listed in admins' isAdmin value to 1?

My name is WatsPlayzROBLOX, and so it should set my leaderstats.isAdmin.Value to 1, but it doesnt do anything, how could i fix this? My script is;

local Players = game:GetService("Players")
local admins = {"WatsPlayzROBLOX"}
local leader = game.Players.LocalPlayer:WaitForChild("leaderstats")
local isAdmin = leader:WaitForChild("isAdmin")
Players.PlayerAdded:Connect(function(player)
	if player.Name == admins then
		player.leaderstats.isAdmin.Value = 1
		print("Player "..player.Name.." is an admin.")
	else
		print("Player"..player.Name.."is not an admin.")
		player.leaderstats.isAdmin.Value = 0
	end
end)

1 comment

0

.

1 answer

Your code:

local Players = game:GetService("Players")
   local admins = {"WatsPlayzROBLOX"}
   local leader = game.Players.LocalPlayer:WaitForChild("leaderstats")
   local isAdmin = leader:WaitForChild("isAdmin")
   Players.PlayerAdded:Connect(function(player)
    if player.Name == admins then 
        player.leaderstats.isAdmin.Value = 1 -- you cannot change the value in a local script
        print("Player "..player.Name.." is an admin.")
    else
        print("Player"..player.Name.."is not an admin.")
        player.leaderstats.isAdmin.Value = 0 -- you cannot change the value in a local script and 0 is default so it's not needed.
    end
   end)

server code in serverscriptservice

local Players = game:GetService("Players")
local admins = {"WatsPlayzROBLOX"}
Players.PlayerAdded:Connect(
    function(player)
        for i, v in pairs(admins) do
            if v == player.Name then
                 player.leaderstats.isAdmin.Value = 1
                print("Player " .. player.Name .. " is an admin.")
            else
                print("Player" .. player.Name .. "is not an admin.")
            end
        end
    end
)

Why my code would work:

player.leaderstats.isAdmin.Value = 1You can only add leader stats value in a server script, so that's why I added a remote event.

if player.Name == admins then -- this would not work because you have to loop through the admin table first

player.leaderstats.isAdmin.Value = 0 0 is default and you cant change it in local script

also check are easily exploitable

4 comments

0

Actually, is not v.Name, just v on line 8

0

thats also easily exploitable, checks should be on server

0

oh, thank you.

0

you're right, lemme edit it

This discussion is preserved as it was. New answers, comments, and votes are closed.