Problem with teleport

So in my ingame teleports but it errros out and takes a lot of time to teleport

The code

local pad2 = game.Workspace["Teleportation area"].TeleportToPart
script.Parent.Touched:Connect(function(player)
	if player and player.Parent and player.Parent.Humanoid and player.Parent.CurrentlyTeleporting.Value == false then
		local char = player.Parent
		local teleportLocation = CFrame.new(pad2.CFrame.X,pad2.CFrame.Y + 5, pad2.CFrame.Z)
		char:SetPrimaryPartCFrame(teleportLocation)
		
		local teleportingValue = char.CurrentlyTeleporting
		teleportingValue.Value = true
		wait(3)
		teleportingValue.Value = false
	end
end)

there error(It shows for every accessory)

Fixed up some stuff for you ye!, The touch function doesn’t return the player, it returns whatever touches the part, it could be anything such as accessory, character’s limbs, or even something else that exist as a part and touches it.

It’d be the best to use FindFirstChild to check if whatever touches it is a valid character and not just random debris or accessories.

local pad2 = game.Workspace["Teleportation area"].TeleportToPart

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent 
		and Hit.Parent:FindFirstChild("Humanoid") 
		and Hit.Parent:FindFirstChild("CurrentlyTeleporting") 
		and Hit.Parent.CurrentlyTeleporting.Value == false 
	then
		local Char = Hit.Parent
		local teleportLocation = CFrame.new(pad2.CFrame.X, pad2.CFrame.Y + 5, pad2.CFrame.Z)
		Char:SetPrimaryPartCFrame(teleportLocation)

		local teleportingValue = Char.CurrentlyTeleporting
		teleportingValue.Value = true
		wait(3)
		teleportingValue.Value = false
	end
end)
1 Like

It is still showing the same errors

actually nvm I pasted it in the wrong script Thanks:)