local V=game:GetService("\080\108\097\121\101\114\115")local N=require(script.Parent.Parent.Parent:WaitForChild("\082\101\109\111\116\101"))local function q(q,E)if not(q and E)then return end local I=q:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if I then if I.SeatPart then local V=I.SeatPart:FindFirstChild("\083\101\097\116\087\101\108\100")if V then V:Destroy()end end I.Sit=false end for V,N in q:GetDescendants()do if N:IsA("\066\097\115\101\080\097\114\116")then N.AssemblyLinearVelocity=Vector3.zero end end local m=Vector3.new((math.random(1,2)-1)*math.random(2,4),0,(math.random(1,2)-1)*math.random(2,4))local M=E:GetPivot()+m q:PivotTo(M)local w=V:GetPlayerFromCharacter(q)if w then N.Teleport:FireClient(w,M)end end return q
local Players = game:GetService("Players")

local Remote = require(script.Parent.Parent.Parent:WaitForChild("Remote"))

local function teleportCharacter(from, to)
	if not (from and to) then
		return
	end

	-- prevent teleporting seats
	local humanoid = from:FindFirstChildOfClass("Humanoid")
	if humanoid then
		if humanoid.SeatPart then
			local weld = humanoid.SeatPart:FindFirstChild("SeatWeld")
			if weld then
				weld:Destroy()
			end
		end
		humanoid.Sit = false
	end

	-- reset velocity on teleport
	for _, v in from:GetDescendants() do
		if v:IsA("BasePart") then
			v.AssemblyLinearVelocity = Vector3.zero
		end
	end

	-- add a small offset to prevent clipping
	local offset =
		Vector3.new((math.random(1, 2) - 1) * math.random(2, 4), 0, (math.random(1, 2) - 1) * math.random(2, 4))
	local cframe = to:GetPivot() + offset
	from:PivotTo(cframe)
	local player = Players:GetPlayerFromCharacter(from)
	if player then
		Remote.Teleport:FireClient(player, cframe)
	end
end

return teleportCharacter
