I need help with domain expansion pls

I’m sort of new to coding and I’m trying to make a domain expansion sort of thing, I got most of the things to work I think but I can’t figure out how to make other players teleport with me.

My code is:
local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local remoteEvent = rs.Remotes.DomainExpansion.RemoteEvent

local main = Instance.new(“Part”)
main.Size = Vector3.new(1,0.5,1)
main.Anchored = true
main.CanCollide = false
main.CanTouch = true
main.Name = “TpPart”

remoteEvent.OnServerEvent:Connect(function(player: Player)
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild(“HumanoidRootPart”)

local clone = main:Clone()

local humPos = character:WaitForChild("HumanoidRootPart").CFrame

clone.CFrame = humPos - Vector3.new(0,3,0)
clone.Parent = game.workspace

ts:Create(clone, info, {Size = Vector3.new(50,0.5,50)}):Play()

local function onCloneTouched(hit)
	
	local hitChar = hit.Parent
	local hitHum = hitChar:WaitForChild("HumanoidRootPart")
	
	if hitChar.Parent ~= player then
		if hitHum then
			print(hitChar)
			hitChar:PivotTo(humPos)
		end
	end	
end

clone.Touched:Connect(onCloneTouched)

task.wait(2)

local floor = Instance.new("Part")
floor.Anchored = true
floor.Size = Vector3.new(100,1,100)
floor.CanCollide = true

local Fclone = floor:Clone()

Fclone.CFrame = humPos - Vector3.new(0,500,0)
Fclone.Parent = game.Workspace

local pos = hum.CFrame
print(pos)

character:PivotTo(Fclone.CFrame - Vector3.new(0,-7,0))

clone:Destroy()

wait(5)
Fclone:Destroy()

character:PivotTo(pos)
print(pos)

end)

Whenever you want to run your teleport do the following:

Create a 3d space which represents the size of your domain,

Use GetPartBoundsInBox or GetPartBoundsInRadius depending if your space is a box or sphere

use FindFirstAncestorOfClass(“Model”) to get each player’s character model

Pivot every found character to their corresponding part within the domain.

You might find it easier to just create a sphere in the map and prevent players from entering or exiting said sphere with collision groups though

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.