Unable to teleport player to part via Remote

I’m simply just trying to teleport a player to a random part in a folder when the remote is fired, the remote is firing properly, but they’re teleporting near the part, not directly on it, I’ve tried about 10 different resolutions and none have been working at all. Any help is much appreciated:

If I move the part I will still spawn near it, not directly on it. Only thing I can think of is using an attachment but surely it should be more simple than that.


Code:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local SpawnPlayerEvent = EventsFolder:WaitForChild("SpawnPlayer")
local Teams = game:GetService("Teams")
local RunService = game:GetService("RunService")

SpawnPlayerEvent.OnServerEvent:Connect(function(Player)
	local NativesTeam = Teams:FindFirstChild("Natives")

	local SpawnsFolder = game.Workspace:FindFirstChild("Spawns")
	local NativesSpawns = SpawnsFolder:FindFirstChild("Natives")

	local spawnPoints = NativesSpawns:GetChildren()
	local randomSpawn = spawnPoints[math.random(1, #spawnPoints)]

	if randomSpawn and randomSpawn:IsA("Part") then
		local character = Player.Character or Player.CharacterAdded:Wait()
		character:WaitForChild("HumanoidRootPart")

		-- Use RunService.Stepped for precise positioning
		RunService.Stepped:Wait()
		character:SetPrimaryPartCFrame(randomSpawn.CFrame + Vector3.new(0, 2, 0)) -- Adjust Y offset if needed
	end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local SpawnPlayerEvent = EventsFolder:WaitForChild("SpawnPlayer")
local Teams = game:GetService("Teams")
local RunService = game:GetService("RunService")

SpawnPlayerEvent.OnServerEvent:Connect(function(Player)
	local NativesTeam = Teams:FindFirstChild("Natives")

	local SpawnsFolder = game.Workspace:FindFirstChild("Spawns")
	local NativesSpawns = SpawnsFolder:FindFirstChild("Natives")

	local spawnPoints = NativesSpawns:GetChildren()
	local randomSpawn = spawnPoints[math.random(1, #spawnPoints)]

	if randomSpawn and randomSpawn:IsA("Part") then
		local character = Player.Character or Player.CharacterAdded:Wait()
		character:WaitForChild("HumanoidRootPart")

		-- Use RunService.Stepped for precise positioning
		RunService.Stepped:Wait()
		character:SetPrimaryPartCFrame(randomSpawn.CFrame * CFrame.new(0, 2, 0)) -- Adjust Y offset if needed
	end
end)

try this.

And why are you using :SetPrimaryPartCFrame? Its deprectated and use PivotTo() instead

Didn’t realize it was deprecated, I changed it but the problem is still occuring.

Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local SpawnPlayerEvent = EventsFolder:WaitForChild("SpawnPlayer")
local Teams = game:GetService("Teams")
local RunService = game:GetService("RunService")

SpawnPlayerEvent.OnServerEvent:Connect(function(Player)
	local NativesTeam = Teams:FindFirstChild("Natives")

	local SpawnsFolder = game.Workspace:FindFirstChild("Spawns")
	local NativesSpawns = SpawnsFolder:FindFirstChild("Natives")

	local spawnPoints = NativesSpawns:GetChildren()
	local randomSpawn = spawnPoints[math.random(1, #spawnPoints)]

	if randomSpawn and randomSpawn:IsA("Part") then
		local character = Player.Character or Player.CharacterAdded:Wait()
		character:WaitForChild("HumanoidRootPart")

		-- Use RunService.Stepped for precise positioning
		RunService.Stepped:Wait()
		character:PivotTo(randomSpawn.CFrame * CFrame.new(0, 2, 0)) -- Adjust Y offset if needed
	end
end)

does this wor

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local SpawnPlayerEvent = EventsFolder:WaitForChild("SpawnPlayer")
local Teams = game:GetService("Teams")
local RunService = game:GetService("RunService")

SpawnPlayerEvent.OnServerEvent:Connect(function(Player)
	local NativesTeam = Teams:FindFirstChild("Natives")

	local SpawnsFolder = game.Workspace:FindFirstChild("Spawns")
	local NativesSpawns = SpawnsFolder:FindFirstChild("Natives")

	local spawnPoints = NativesSpawns:GetChildren()
	local randomSpawn = spawnPoints[math.random(1, #spawnPoints)]

	if randomSpawn and randomSpawn:IsA("Part") then
		local character = Player.Character or Player.CharacterAdded:Wait()
		character:WaitForChild("HumanoidRootPart")

		-- Use RunService.Stepped for precise positioning
		RunService.Stepped:Wait()
		character.PrimaryPart.CFrame = randomSpawn.CFrame+Vector3.new(0,2,0) -- Adjust Y offset if needed
	end
end)
1 Like

The strange thing is that it works in a blank baseplate but doesn’t work in my actual game, I think the issue maybe that the location of the parts is really far back or something, I have no idea but I’ll mark yours as a solution. Thanks.

1 Like

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