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?
I personally prefer this method as it is much simpler.
01 | local hasPower = { |
02 | [ "gitrog" ] = true , |
03 | [ "spartanlord456" ] = true --add as many names as you need |
04 | } |
05 |
06 | game.Players.PlayerAdded:connect( function (player) |
07 | player.CharacterAdded:connect( function (character) |
08 | if hasPower [ player.Name ] then |
09 | --power script here |
10 | end |
11 | end ) |
12 | end ) |
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;
01 | game.Players.PlayerAdded:Connect( function (plr) -- fires when player join the game |
02 |
03 | local PlayerRole = Instance.new( 'Folder' ) -- Holds the roles |
04 | PlayerRole.Parent = plr |
05 | PlayerRole.Name = 'PlayerRole' |
06 | wait() -- wait's for player to load in |
07 | local AdminRole = Instance.new( 'BoolValue' ) -- a bool value |
08 | AdminRole.Parent = PlayerRole -- goes inside player |
09 | AdminRole.Name = 'AdminRole' |
10 | AdminRole.Value = false -- no admin |
11 |
12 | if plr.Name = = "Your username" then |
13 | AdminRole.Value = true |
14 | end |
15 | end ) |
and then in your script that gives superpowers just do something like this;
1 | if AdminRole.Value = = true then |
2 | -- gives player power |
3 | end |
This is an easy way.
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.
01 | local p = { 'PlayerName' , 'player' } -- remove the {'s and the extra "player" then it will be a singular person |
02 | game.Players.PlayerAdded:connect( function (plr) |
03 | if plr.Name = p then |
04 |
05 |
06 | -- code here |
07 |
08 |
09 | end |
10 | end ) |
But of course, Its not very efficient, plenty of methods that are better then that such as.
1 | game.Players.PlayerAdded:connect( function (plr) |
2 | if plr.Name = = 'PlayerName' then |
3 |
4 | -- code here |
5 |
6 | end |
7 | end ) |
But I prefer my way, :)
Anyways hope this helps.