Do I put it like
{userid, userid}
or
{“userid”, “userid”}
Do I put it like
{userid, userid}
or
{“userid”, “userid”}
No you should put UserId as number not as string
local List = {} -- List of player UserIds'
local TPS = game:GetService("TeleportService")
game.Players.PlayerAdded:Connect(function(player)
if List == nil then
List = {}
end
for _, userId in pairs(List) do
if tostring(player.UserId) == tostring(userId) or tostring(player.Name) == tostring(userId) then
TPS:Teleport(123456789, player) -- Place id here
else
print(player.Name .. "isn't in the list!")
player:Kick("You were not on the list!") -- Random stuff
end
end
end)
Here Use this better code
This one works so you can use names and UserIds
Same error happens
Can you show us ur entire code.
actually hold on i think im editting the wrong script on the wrong game
Ohh, ok well now explains it lol
I thought my scripting abilites had failed me lol.
Off-topic: I was almost gonna give up
I mean it doesn’t teleport still- I used a random game I recently played to test it with, should I use one of my games instead or what
local List = {}
local TPS = game:GetService("TeleportService")
game.Players.PlayerAdded:Connect(function(player)
if List == nil then
List = {}
end
for _, userId in pairs(List) do
if tostring(player.UserId) == tostring(userId) then
print("allowed")
else
TPS:Teleport(2960777560, player) -- Place id here
end
end
end)
also I needed to make it so if they arent on the list they get teleported not if they are
You need to put the UserIds or player names in the List
doesnt what i have tp if its not on the list tho
Should Probably work
local List = {
2391075837
}
local TPS = game:GetService("TeleportService")
game.Players.PlayerAdded:Connect(function(player)
if List == nil then
print("List is empty")
end
for _, userId in pairs(List) do
if userId == player.UserId then
print("allowed")
else
TPS:Teleport(2960777560, player) -- Place id here
end
end
end)
Yeah it does, thanks!
No problem! Make a post whenever needed! Have a great day!
Also thanks to @N3xcon for making some stuff better in the script!
Not possible since there is a few seconds delay between teleporting.
Hey! I’m sorry to bump this now that it’s a solution, but that is not a good idea…
Say for instance, someone joins but their UserID isn’t the first on the list… Instead it’s the second.
In this scenario, their ID does NOT match the first, and they’re teleported anyways, even though they’re on the list.
Give me a moment and I will edit this with a proper code block for this intended approach.
local IntendedDestination = 0; -- Place the intended destination PlaceID.
local AllowedUserIDs = {
2391075837, -- OP's userid
0, -- continue this array for more ids.
}
local TeleportService = game:GetService("TeleportService");
local PlayerService = game:GetService("Players");
local function PlayerJoined(Player) -- valid function for a PlayerAdded connection, neat & tidy.
local PlayerID = Player.UserId
local Passed = table.find(AllowedUserIDs, PlayerID) -- find returns index of the matched value or nil
if Passed == nil then -- If Passed == nil, or in other words, there is no matching Value in the Array...
TeleportService:Teleport(IntendedDestionation, Player) -- ... then teleport them out!
end
end
PlayerService.OnPlayerAdded:Connect(PlayerJoined)
Edit: There we go! A good piece of code, please do let me know if there are any errors.