Teleporting a player not working

Hello, i’ve made a plot system with ownership, everything else works but not the teleporting, no errors in outputs or yellow warnings, if u have any clue whats going on please let me know. (MODULE SCRIPT) (SERVERSCRIPTSERVICE)

Function that handles teleporting:

function PlotService:TeleportToPlot(player)
	local plot = self:GetPlot(player)
	if plot then
		local spawn = plot:FindFirstChild("SpawnLocation")
		if spawn and player.Character and player.Character.PrimaryPart then
			player.Character:SetPrimaryPartCFrame(spawn.CFrame + Vector3.new(0,5,0))
		end
	end
end

Full module script:

local PlotsFolder = workspace:WaitForChild("Aquariums")

local PlotService = {}
local plotOwners = {}

local FORCE_ASSIGN = false
local FORCED_PLOT_NAME = "Plot1"

function PlotService:GetPlotOwners()
	return plotOwners
end

function PlotService:GetPlot(player)
	for plot, owner in pairs(plotOwners) do
		if owner == player then
			return plot
		end
	end
	return nil
end

function PlotService:AssignPlot(player)
	if FORCE_ASSIGN then
		local forcePlot = PlotsFolder:FindFirstChild(FORCED_PLOT_NAME)
		if forcePlot then
			for p, owner in pairs(plotOwners) do
				if owner == player or p == forcePlot then
					self:FreePlot(owner)
				end
			end
			
			plotOwners[forcePlot] = player
			
			local ownerTag = forcePlot:FindFirstChild("Owner") or Instance.new("ObjectValue")
			ownerTag.Name = "Owner"
			ownerTag.Value = player
			ownerTag.Parent = forcePlot
			
			local signGui = forcePlot:FindFirstChild("Sign") and forcePlot.Sign:FindFirstChildWhichIsA("SurfaceGui")
			local label = signGui and signGui:FindFirstChildWhichIsA("TextLabel")
			if label then label.Text = player.Name end
			
			if player.Character then
				player.Character:WaitForChild("HumanoidRootPart", 3)
				self:TeleportToPlot(player)
			end
			player.CharacterAdded:Connect(function()
				self:TeleportToPlot(player)
			end)

			return forcePlot
		end
	end
	
	for _, plot in ipairs(PlotsFolder:GetChildren()) do
		if not plotOwners[plot] then
		plotOwners[plot] = player
		local ownerTag = plot:FindFirstChild("Owner") or Instance.new("ObjectValue")
		ownerTag.Name = "Owner"
		ownerTag.Value = player
		ownerTag.Parent = plot
		
		local signGui = plot:FindFirstChild("Sign") and plot.Sign:FindFirstChildWhichIsA("SurfaceGui")
		local label = signGui and signGui:FindFirstChildWhichIsA("TextLabel")
		if label then label.Text = player.Name end
		
			if player.Character then
				player.Character:WaitForChild("HumanoidRootPart", 3)
				self:TeleportToPlot(player)
			end
		player.CharacterAdded:Connect(function()
			self:TeleportToPlot(player)
		end)
		
		return plot
	end
end
return nil
end

function PlotService:TeleportToPlot(player)
	local plot = self:GetPlot(player)
	if plot then
		local spawn = plot:FindFirstChild("SpawnLocation")
		if spawn and player.Character and player.Character.PrimaryPart then
			player.Character:SetPrimaryPartCFrame(spawn.CFrame + Vector3.new(0,5,0))
		end
	end
end

function PlotService:FreePlot(player)
	for plot, owner in pairs(plotOwners) do
		if owner == player then
			plotOwners[plot] = nil
			local ownerTag = plot:FindFirstChild("Owner")
			if ownerTag then ownerTag:Destroy() end
			
			local signGui = plot:FindFirstChild("Sign") and plot.Sign:FindFirstChildWhichIsA("SurfaceGui")
			local label = signGui and signGui:FindFirstChildWhichIsA("TextLabel")
			if label then label.Text = "No one" end
			
			return true
		end
	end
	return false
end



return PlotService
1 Like

What does it error? Cant really help without knowing what’s wrong (I could but it’s just easier to have information :melting_face: )

1 Like

Hello, there is no errors in the output neither yellow warnings

1 Like

Thought you said there was :pray:


function PlotService:TeleportToPlot(player)
	local plot = self:GetPlot(player)
	if plot then
		local spawn = plot:FindFirstChild("SpawnLocation")
		if spawn and player.Character and player.Character.PrimaryPart then
			player.Character.HumanoidRootPart.CFrame = spawn.CFrame + Vector3.new(0,5,0)
		end
	end
end

1 Like

Thanks but still doesnt work :C

use print statements or breakpoints to see if it’s not making it past the if statments

Never ever ever move a player by moving their HumanoidRootPart. You can call :MoveTo() on the player’s character just like any other model.

that’s wild

That’s even more wild then I thought :pray:

Umm, i dont think thats the problem tho. i wouldnt say :MoveTo() is better. And hardly say never move a player by moving their HumanoidRootPart

Yes i will try the print statements thank you

Add print statements, it’s probably not making it past one of the if statements and not teleporting

so everything prints even the teleport line prints, player still wont be moved its very weird

nevermind i found the solution, made changes to set the players primary part to humanoidrootpart, added some wait so the player can load, Thank you for the breakpoints ideas should have thought about it sooner!

You should use PVInstance:PivotTo() instead, it doesn’t even require a primary part unlike SetPrimaryPartCFrame

SetPrimaryPartCFrame is also deprecated

1 Like

Moving a player’s HRP can cause offsets from the HRP and the visible character.

I didn’t know that actually, i always move the HumanoidRootPart

Would this cause major issues?

It depends if you ever get the position of the HRP in your code. For example if you had a weapon that shot projectiles from the HRP it would spawn the projectiles at the offset position. It’s just good practice to not set the position of the HRP.