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

How can I make a script usable by a specific person?

Asked by 7 years ago

I am making a game that has powers and such, and I made a custom power. I don't want other people to use my custom power, so how do I make it so that I can only use it?

3 answers

Log in to vote
0
Answered by
gitrog 326 Moderation Voter
7 years ago

I personally prefer this method as it is much simpler.

local hasPower = {
        ["gitrog"] = true,
        ["spartanlord456"] = true --add as many names as you need
    }

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if hasPower[player.Name] then
            --power script here
        end
    end)
end)
Ad
Log in to vote
4
Answered by 7 years ago

You can use game.Players.PlayerAdded:Connect(function() to check if the player is a certain player.

Add a Server Script into **ServerScriptService** and then type in this code;

game.Players.PlayerAdded:Connect(function(plr) -- fires when player join the game

    local PlayerRole = Instance.new('Folder') -- Holds the roles
    PlayerRole.Parent = plr
    PlayerRole.Name = 'PlayerRole'
    wait() -- wait's for player to load in
    local AdminRole = Instance.new('BoolValue') -- a bool value
    AdminRole.Parent = PlayerRole -- goes inside player
    AdminRole.Name = 'AdminRole'
    AdminRole.Value = false -- no admin

    if plr.Name == "Your username" then
        AdminRole.Value = true
    end
end)

and then in your script that gives superpowers just do something like this;

if AdminRole.Value == true then
    -- gives player power
end

This is an easy way.

Log in to vote
-1
Answered by
IcyEvil 260 Moderation Voter
7 years ago

You can always check a players name.

When I am trying to check to see if there is a certain player in the game I like to use this method.

local p = {'PlayerName', 'player'} -- remove the {'s and the extra "player" then it will be a singular person
game.Players.PlayerAdded:connect(function(plr)
if plr.Name = p then


-- code here


end
end)

But of course, Its not very efficient, plenty of methods that are better then that such as.

game.Players.PlayerAdded:connect(function(plr)
if plr.Name == 'PlayerName'then

-- code here

end
end)

But I prefer my way, :)

Anyways hope this helps.

0
line 3 Goulstem 8144 — 7y
0
I know it's been over a year, but I forgot to accept your answer. I'll be doing that right now. Sorry! spartanlord456 19 — 6y

Answer this question