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

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

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

✓ Accepted answer

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)

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.

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.

2 comments

0

line 3

0

I know it's been over a year, but I forgot to accept your answer. I'll be doing that right now. Sorry!

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