At the moment, it just currently sends me below the 'baseplate' area and I fall to my death, repeatedly. I've got it to sometimes spawn me at the home spawn.

What i'm TRYING to do is save a players position whenever they leave, and if they die, get sent back to the home.

But anyways, when character is added, it takes the position data and teleports, that should work.

when character is removed however, is where my problem is, i think. I seem to get these bugs that loop myself into confusion. I'm not sure at this point what i'm doing wrong. Point me in the right direction please!

local function onCharacterAdded(character) --Teleport player
	local player = game.Players:GetPlayerFromCharacter(character)
	local data = player:WaitForChild("PlayerData")
	local stats = data:WaitForChild("PlayerStats")
	
	local TimeJoined = game.Lighting.ClockTime
	character:FindFirstChild("TimeJoined").Value = TimeJoined
	local X = stats.PositionX.Value
	local Y = stats.PositionY.Value
	local Z = stats.PositionZ.Value
	character.HumanoidRootPart.CFrame = CFrame.new(X,Y,Z)
end
 
local function onCharacterRemoving(character)
	local player = game.Players:GetPlayerFromCharacter(character)
	local data = player:WaitForChild("PlayerData")
	local stats = data:WaitForChild("PlayerStats")
	local birth = stats.Birth.Value
	if character.Death == 1 then --character is dead, changing position data to home.
		local birtharea = workspace:FindFirstChild(birth).Enter
		local spawnX = birtharea.Position.X
		local spawnY = birtharea.Position.Y
		local spawnZ = birtharea.Position.Z
	
		stats.PositionX.Value = spawnX
		stats.PositionY.Value = spawnY
		stats.PositionZ.Value = spawnZ
		print(birth, stats.PositionX.Value, stats.PositionY.Value, stats.PositionZ.Value)
		stats.Lives.Value = stats.Lives.Value-1
	else --leaving?
		local currentX = character.Head.Position.X
		local currentY = character.Head.Position.Y
		local currentZ = character.Head.Position.Z
	
		stats.PositionX.Value = currentX
		stats.PositionY.Value = currentY
		stats.PositionZ.Value = currentZ	
	end
end

And my 'setter' code, although not necessary but was mostly a test to see if running it before dying set the position faster, or at all. Honestly, didn't seem to do anything.

local character = script.Parent
if not character then repeat wait() until character end
local player = game.Players:FindFirstChild(character.Name)
local playerData = player:WaitForChild("PlayerData")
local TimeJoined = character:WaitForChild("TimeJoined") 
local Death = character:WaitForChild("Death") 

while wait(.1) do
	if TimeJoined == game.Lighting.ClockTime then
		playerData.PlayerStats.Days.Value = playerData.PlayerStats.Days.Value+1
	end
	if character.Humanoid.Health > 5 then
		wait(1.5)
		Death.Value = 0
	else
		wait(1.5)
		Death.Value = 1
	end
end

4 comments

0

Try getting the script to print the x, y, and z coordinates and verify if it's correct as when the character was removed. From there, you may be able to see if it's just teleporting to to nil location instead.

0

It prints off the home name and coords just fine. it shouldnt however, teleport me to my previous location because im dying from the teleportation below the map...                        Maybe it's my setter code. No way to find out until after work for me.

0

You don't need NumberValue for X,Y,Z All you need is CFrameValue. you can set CFrameValue in your script. Ex:CFrameValue.Value = character.HumanoidRootPart.CFrame // character.HumanoidRootPart.CFrame = CFrameValue.Value

0

I was previously doing this, i was converting the coords tostring and repeating them back in number form, same thing just different method. I switched to seperate values for a little more control, as string manipulation is almost ridiculous to do