this script should teleport me to a different game when i touch the part but it doesnt do that exact thing, why?
local TeleportService = game:GetService("TeleportService")
local Place = (game id)
script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(Place, player)
end
end)
I think i’d be preferable to have a check to see if hit.Parent is indeed a character or not another object.
local TeleportService = game:GetService("TeleportService")
local Place = (game id)
script.Parent.Touched:connect(function(hit)
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(Place, player)
end
end
end)
i added what u said and now theres no error but it doesnt teleport me at all.
local TeleportService = game:GetService("TeleportService")
local Place = (game id)
local part = script.Parent
script.Parent.Touched:connect(function(hit)
if part:FindFirstChildOfClass("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(Place, player)
end
end
end)