This is helpful, if you only want your game not to be published publictly (Only your friends can play) so lets get started.
firstly we will need a PlayerAdded function, insert a script in ServerScriptService then copy this function:
game.Players.PlayerAdded:Connect(function(player) --The parameter (player) is the player that will join your game.
end)
then we will need to define a variable on top the PlayerAdded function, name it like ‘MyUserId’, ‘UserId’ Etc.
local MyUserId = 2554983508 -- Replace your actual UserId
it would look something like this:
local MyUserId = 2554983508 -- Replace your actual UserId
game.Players.PlayerAdded:Connect(function(player) --The parameter (player) is the player that will join your game.
end)
after you’ve than that, you have two option, First option is if you want to kick the player when its not your friend. and the second option is to let them in or do some pranks if its your friend.
we will need to add this if else statement inside the PlayerAdded function:
if player:IsFriendsWith(MyUserId) then
-- Do something if the player is your friend.
else
print("Im not your friend! im kicking you.")
player:Kick("Reason Here")
end
if you want to only kick the player if its not your friend use this if statement:
if not player:IsFriendsWith(MyUserId) then
player:Kick("Reason Here")
end
choose an if statement then put that below the PlayerAdded Function.
local MyUserId = 2554983508 -- Replace your actual UserId
game.Players.PlayerAdded:Connect(function(player) --The parameter (player) is the player that will join your game.
if player:IsFriendsWith(MyUserId) then
-- Do something if the player is your friend.
else
print("Im not your friend! im kicking you.")
player:Kick("Reason Here")
end
-- ...
end)
and then your DONE, I hope this tutorial helps.