You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am making a game similar to rainbow friends, but I don’t know how to teleport a group of players from the lobby to the sub game. I want to teleport all players touching a part every 30 seconds.
-
What is the issue? Include screenshots / videos if possible!
When time runs out and players are supposed to teleport, nothing happens
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried a YT tutorial I found but it didn’t help and neither did the weird roblox AI thing
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
this is my first post and I am pretty new to coding lua (I watched a 13 part scripting tutorial and took the roblox studio lessons but that’s about it.
local circle = script.Parent
local timer = 30
while wait(1) do
timer -=1
print(timer)
if timer == 0 then
timer = 30
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local PlayerTable = circle:GetTouchingParts()
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent.Humanoid then return end
table.remove(PlayerTable, i)
end
TeleportService:TeleportAsync(teleportID, PlayerTable) --Teleport players
end
end
1 Like
Hey there, a 13 part scripting series? Sounds familiar. Anyways can you try printing out the table of players aswell as answer the following questions:
Is this a regular/server script?
WHAT I THINK THE PROBLEM IS
Secondly I think that even if you are finding the part of a player you aren’t actually getting the player, to do this in the loop where you find the parts of the player you want to try and get:
local plr = game.Players:GetPlayerFromCharacter(v.Parent)
Also add the plr
to the table not i
Also I just noticed you are doing a table.remove and not adding the players to the table?
2 Likes
This is a normal script and is a child of the circle part.
Where would I put the variable? At the top?
(I took the tutorial from a YT named codebro29)
1 Like
Aha, I also have a 13 part scripting series. I think the best thing to do here is first rename some things for clarity.
I would first rename PlayerTable
to TouchingParts
. Then we will do what I said in the beginning as well as making a new table to store the actual players:
local TouchingParts = circle:GetTouchingParts()
local PlayerTable = {}
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent.Humanoid then return end
local plr = game.Players:GetPlayerFromCharacter(v.Parent)
if not plr then warn("player not found"); continue end
table.insert(PlayerTable, plr)
end
Untested code, might work but mainly for concept
2 Likes
okay, thanks, quick question: could you explain GetPlayerFromCharacter(v.Parent) and also, is the if v.Parent.Humanoid then return end still necessary?
I was given an error: Humanoid is not a valid member of Workspace “Workspace”
local circle = script.Parent
local timer = 30
while wait(1) do
timer -=1
print(timer)
if timer == 0 then
timer = 30
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local TouchingParts = circle:GetTouchingParts()
local PlayerTable = {}
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent.Humanoid then return end
local plr = game.Players:GetPlayerFromCharacter(v.Parent)
if not plr then warn("player not found"); continue end
table.insert(PlayerTable, plr)
end
TeleportService:TeleportAsync(teleportID, PlayerTable) --Teleport players
end
end
2 Likes
Yeah this is just checking that the thing found has a Humanoid which in most games will only be a players character.
Yes this method gets the Player object from a the character model, in this code the part (v) is a part in the player (like a leg) so it’s parent (v.Parent) is the character model
2 Likes
ok that makes sense. Should the if v.Parent.Humanoid then return end be wrapped around something though?
1 Like
Ok i would first recommend to change the following:
To:
if v.Parent:FindFirstChild("Humanoid") then return end
Good question, the answer is no because that is what we call a guard clause, the return will just exit the script, in this case we should actually change the return to a continue so if we don’t find a humanoid in the parent of that part we will just go right to the next iteration in the loop.
2 Likes
this time I was given 14:07:27.125 player not found - Server - Script:22
14:07:27.125 Invalid list of players for teleport.
1 Like
Ok so the Player Not found is something I added into to code if, well, the player isn’t found. Try changing the Plr variable to this:
local plr = game.players:GetPlayerFromCharacter(v.Parent) or game.players:GetPlayerFromCharacter(v.Parent.Parent)
In case it touches an accessory.
Then what we should also check before adding the player to the table is that they aren’t already in the table. So right above the line with the table.insert
add this:
if table.find(PlayerTable, plr) then continue end
Another guard clause that will make it not add the player more than once
2 Likes
Now I got an error I’ve never seen before,
14:12:14.514 players is not a valid member of DataModel “Game”
local circle = script.Parent
local timer = 30
while wait(1) do
timer -=1
print(timer)
if timer == 0 then
timer = 30
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local TouchingParts = circle:GetTouchingParts()
local PlayerTable = {}
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent:FindFirstChild("Humanoid") then return end
local plr = game.players:GetPlayerFromCharacter(v.Parent) or game.players:GetPlayerFromCharacter(v.Parent.Parent)
if not plr then warn("player not found"); continue end
table.insert(PlayerTable, plr)
end
TeleportService:TeleportAsync(teleportID, PlayerTable) --Teleport players
end
end
1 Like
That is my fault the p
in players
should be capitalized:
local plr = game.Players:GetPlayerFromCharacter(v.Parent) or game.Players:GetPlayerFromCharacter(v.Parent.Parent)
2 Likes
error is 14:16:06.455 player not found - Server - Script:22
14:16:06.455 Invalid list of players for teleport.
local circle = script.Parent
local timer = 30
while wait(1) do
timer -=1
print(timer)
if timer == 0 then
timer = 30
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local TouchingParts = circle:GetTouchingParts()
local PlayerTable = {}
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent:FindFirstChild("Humanoid") then return end
local plr = game.Players:GetPlayerFromCharacter(v.Parent) or game.Players:GetPlayerFromCharacter(v.Parent.Parent)
if not plr then warn("player not found"); continue end
table.insert(PlayerTable, plr)
end
TeleportService:TeleportAsync(teleportID, PlayerTable) --Teleport players
end
end
1 Like
Ok that’s odd, can you please print out v
above the plr
variable and tell me what the results are
2 Likes
it printed
Baseplate - Server - Script:20
14:19:29.874 player not found - Server - Script:23
14:19:29.875 Invalid list of players for teleport.
oops I put it in the wrong spot lemme try again
it printed the same thing.
local circle = script.Parent
local timer = 10
while wait(1) do
timer -=1
print(timer)
if timer == 0 then
timer = 10
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local TouchingParts = circle:GetTouchingParts()
local PlayerTable = {}
for i,v in pairs(circle:GetTouchingParts()) do
if v.Parent:FindFirstChild("Humanoid") then return end
print(v)
local plr = game.Players:GetPlayerFromCharacter(v.Parent) or game.Players:GetPlayerFromCharacter(v.Parent.Parent)
if not plr then warn("player not found"); continue end
table.insert(PlayerTable, plr)
end
TeleportService:TeleportAsync(teleportID, PlayerTable) --Teleport players
end
end
I was standing on it too
1 Like
Oh my gosh, I’m so dumb.
Here:
Change to:
if not v.Parent:FindFirstChild("Humanoid") then return end
2 Likes
um nothing happened at all, no prints or anything, not even the teleport failed error message… (you cannot teleport from studio)
the timer still printed
the game IS private and the game teleporting too is ALSO private so maybe that has something to do with it
1 Like
I’m aware, the issue is the GetTouchingParts
isn’t detecting your character. Unfortunately this happens a lot, I can write something very consistent when I get home but its to complex to explain without example. I will be able to help you further in about 2 hours (maybe)
2 Likes
I could try setting can collide to 0 and raising it above ground so it touches more of you… would that help?
1 Like
Maybe try raising it slightly off the ground
2 Likes