Okay. Let's create a script that detects if something has touched the part:
script.Parent.Touched:Connect(function(hit)
end)
But we don't know if the thing that touched the part is a player. Let's check if that thing that touched has a child named "Humanoid" (every player's character has a child named "Humanoid" in it):
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
end
end)
Okay. So now, let's get the player by the hit's parent's name (the player's character's name is always the same as the player's name in game.Players):
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:WaitForChild(hit.Parent.Name)
end
end)
Now, let's teleport it. In order to do that, we have to get the "TeleportService" from the game:
local TeleportService = Game:GetService("TeleportService")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:WaitForChild(hit.Parent.Name)
TeleportService:Teleport(YOUR GAME ID HERE, player)
end
end)
This script has to be inserted in the part you want the player to touch.
Hope this helped!
2 comments
It helped a lot, Thanks!
No problem! But can you accept it?