Need help with teleport script!

I need help making it to where the script only teleports players
Here’s the current script:

local TeleportPart1 = script.Parent.TeleportPart1
local TeleportPart2 = script.Parent.TeleportPart2

TeleportPart1.Touched:Connect(function(hit)
	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w then
		w.CFrame = TeleportPart2.CFrame + Vector3.new(0, 5, 0)
		TeleportPart2.CanTouch = false
		wait(1)
		TeleportPart2.CanTouch = true
	end
end)

TeleportPart2.Touched:Connect(function(hit)
	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w then
		w.CFrame = TeleportPart1.CFrame + Vector3.new(0, 5, 0)
		TeleportPart1.CanTouch = false
		wait(1)
		TeleportPart1.CanTouch = true
	end
end)

You can get the help of some free models :smiley:

	local w = hit.Parent:FindFirstChild("HumanoidRootPart")
	if w then
		local Character = w.Parent; -- To get the character
		local Player = game.Players:GetPlayerFromCharacter(Character) -- To get the player that has the Character

		if Player then -- Check if the player exists, if yes, its a player, if not, its an NPC
			w.CFrame = TeleportPart2.CFrame + Vector3.new(0, 5, 0)
			TeleportPart2.CanTouch = false
			wait(1)
			TeleportPart2.CanTouch = true
		end
	end
1 Like

didnt work :frowning: It has an error where it says hit and it only teleports me once.

i would rather do this. use for reference:

server

local part = script.Parent
local teleportationPart = game.Workspace.SpawnLocation

part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.RootPart.CFrame = teleportationPart.CFrame + Vector3.new(0, 10, 0)
	end
end)
1 Like

What do you mean by “it says hit”? And by teleporting once? If there are any errors in the output, please copy them and show me

nevermind it was my mistake. Thank you!

You need to check if the hit.Parent is a player character then you can teleport them, like this :

local Players = game:GetService("Players")

local SpecifiedPart = wheredidstoreit
local TeleportTo = workspace.TeleportPartIdk.CFrame

SpecifiedPart.Touched:Connect(function(hit)
   if Players:GetPlayerFromCharacter(hit.Parent) then
   	local Character = hit.Parent -- The player's character obviously.
   	Character.HumanoidRootPart.CFrame = TeleportTo + Vector.new(0,5,0) -- Teleport them
   	-- You change the "TeleportTo" to the another CFrame if you want.
   	-- I am obviously not going to add that because, you can take this script as an example and make a small changes to it.
   end
end)