Player is teleporting to 0,0,0 Instead of where its actually meant to go

I’m currently trying to set up a Spawn-point system where the player sets their spawn themselves by interacting with a proximity prompt. Once this proximity prompt has been triggered it will change the value of a string value attached to each player to the position coordinates to a corresponding TP part and teleport them to that set of coordinates 1 second after the character added event.

But for some reason, when I try to move the HumanoidRootPart’s CFrame with HumanoidRootPart.CFrame = CFrame.new(Vector3.new(activesp)) It teleports the player to 0,0,0 instead of activesp (Which stands for active spawn point aka the stringvalue.) and I’m completely stumped and tired. This is ran from a local script which gets the updated string value from a server sided change of the stringvalue from a remote event and it datastores all fine everything works the value changes and all but for some reason it just teleports the player to 0,0,0

Here is my code below:
LocalScript:
local Players = game:GetService(“Players”)

local Plr = Players.LocalPlayer
local Char = Plr.Character
local SPoints = workspace.Spawnpoints

– Active spawnpoint variable.
task.wait(0.1)
local activesp = Plr.SPfolder.activeSP

local Remote = game.ReplicatedStorage.PlayerInfo
local Remote2 = game.ReplicatedStorage.PlayerInfo2
local function SaveSP()
Remote:FireServer(activesp)
end

local SP1 = SPoints.SP1
local PP1 = SP1.ProxPrompt.ProximityPrompt

local SP2 = SPoints.SP2
local PP2 = SP2.ProxPrompt.ProximityPrompt

local SP3 = SPoints.SP3
local PP3 = SP3.ProxPrompt.ProximityPrompt

– Stands for “Active SpawnPoint Model”
local ASPM = nil

– VFX functions
local function SPVFXon()
ASPM.Veins.Color = Color3.new(1, 1, 1)
ASPM.SPeffects.ParticleEmitter.Enabled = true
end

local function SPVFXoff()
if ASPM == nil then
print(“ASPM is Nil”)
else
ASPM.Veins.Color = Color3.new(0, 0, 0)
ASPM.SPeffects.ParticleEmitter.Enabled = false
end
end

– Proximity prompts reset function (Turns all proximity prompts in the spawnpoints folder on)
local function ProxReset()
for _, descendant in ipairs(SPoints:GetDescendants()) do
if descendant:IsA(“ProximityPrompt”) then
descendant.Enabled = true
end
end
end

– Respawning function that teleports player to the active spawnpoint.
Plr.CharacterAdded:Connect(function(Char)
print(“character spawned”)
local hrp = Char:WaitForChild(“HumanoidRootPart”)
task.wait(0.1)
hrp.CFrame = CFrame.new(Vector3.new(activesp))
print(hrp.CFrame)
print(activesp)
end)

– Proximity prompt functions that changes active spawn point
PP1.Triggered:Connect(function(Plr)
SPVFXoff()
if activesp == activesp then
activesp = SP1.TP.Position
ASPM = SP1
SPVFXon()
ProxReset()
SaveSP()
PP1.Enabled = false
end
end)

PP2.Triggered:Connect(function(Plr)
SPVFXoff()
if activesp == activesp then
activesp = SP2.TP.Position
ASPM = SP2
SPVFXon()
ProxReset()
SaveSP()
PP2.Enabled = false
end
end)

PP3.Triggered:Connect(function(Plr)
SPVFXoff()
if activesp == activesp then
activesp = SP3.TP.Position
ASPM = SP3
SPVFXon()
ProxReset()
SaveSP()
PP3.Enabled = false
end
end)

Server script does all the data stuff:
local Dataservice = game:GetService(“DataStoreService”)
local Datastore = Dataservice:GetDataStore(“DataStorage”)
local Players = game:GetService(“Players”)
local PlayerInfo = game.ReplicatedStorage.PlayerInfo
local PlayerInfo2 = game.ReplicatedStorage.PlayerInfo2

PlayerInfo.OnServerEvent:Connect(function(player, activesp)
player.SPfolder.activeSP.Value = activesp
print(activesp)
end)

game.Players.PlayerAdded:Connect(function(player)
local SPfolder = Instance.new(“Folder”)
local SP = Instance.new(“StringValue”)
SPfolder.Name = “SPfolder”
SPfolder.Parent = player
SP.Name = “activeSP”
SP.Parent = SPfolder
local playerUserID = “Player_”…player.UserId

-- loading data

local data
local success, errormessage = pcall(function()
	data = Datastore:GetAsync(playerUserID)
end)

if success then
	player.SPfolder.activeSP.Value = data
	print("data got",player.SPfolder.activeSP.Value)
else
	print("no prior data")
	-- set our data to whatever the string is
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = “Player_”…player.UserId

local data = player.SPfolder.activeSP.Value

Datastore:SetAsync(playerUserID, data)

end)

Ask away at any explanation of what does what, I’m still rather new to coding and there is bound to be mistakes in this.

If you need output just ask i’ll be monitoring this for a few hours before I go off to bed this has given me a headache for the past 3 hours.

First of all, learn how to format your code. Second of all, do Player.Character:PivotTo(CFrame) than HRP.CFrame = CFrame

1 Like

Sorry for the slow reply, I don’t know how to format my code in the dev forums its never explained how to do that.
And that didnt work, it only brought up more errors.

Try this instead:

character:PivotTo(CFrame.new(Vector3.new(activesp.Value)))