Spawnpoints not working after death

I have a checkpoint system for my open-world parkour game, and the system seems to work fine and you respawn at the last checkpoint you touched when you die, the only issue is that whenever you respawn, the checkpoints no longer activate because they think the the objectvalue (what im using to determine the spawn location) is equal to the checkpoints object, even though it isnt. I might just be having a brain fart, but im kinda stumped on this. Heres the scripts:

Script inside checkpoints: (decalholder name is different for each checkpoint)

local TS = game:GetService("TweenService")
local PS = game:GetService("Players")

local model = script.Parent
local decalHolder = model:WaitForChild("1")
local hitbox = model:WaitForChild("Hitbox")

local offset = 360
local tweenTime = 1

local tweenInfo = TweenInfo.new(tweenTime, 
	Enum.EasingStyle.Circular,
	Enum.EasingDirection.Out
)

local tween = TS:Create(decalHolder, tweenInfo, {Orientation = decalHolder.Orientation + Vector3.new(0, offset, 0)})

local db = true
hitbox.Touched:Connect(function(hit)
	if db then
		if hit.Parent:FindFirstChild("Humanoid") then
			if not hit.Parent:FindFirstChild("NPC") then
				db = false
				local player = PS:GetPlayerFromCharacter(hit.Parent)
				local leaderstats = player:WaitForChild("leaderstats", 10)
				local spawnPoint = leaderstats:WaitForChild("spawnPoint")
				if spawnPoint.Value == decalHolder then return end
				spawnPoint.Value = decalHolder
				print(spawnPoint.Value)
				tween:Play()
				task.wait(tweenInfo.Time + 1)
				db = true
			end
		end
	end
end)

Script for spawning: (server script service)

local PS = game:GetService("Players")

PS.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder", player)
	folder.Name = "leaderstats"
	local spawnNum = Instance.new("ObjectValue", folder)
	spawnNum.Name = "spawnPoint"
	spawnNum.Value = nil
	
	player.CharacterAdded:Connect(function(character)
		local location = spawnNum.Value
		if not location then return end
		character:PivotTo(location.Attachment.WorldCFrame)
	end)
end)

Any and all help is greatly appreciated, so thank you in advance.

Maybe this?

spawnPoint.Value = decalHolder.Position

I don’t think an objectValue will take a Vector3 position

I’ve fixed the issue! It was kind of a simple fix, but basically the line that checks if the objectValue is equal to the spawn’s decalHolder part had return end at the end, WITHOUT setting the debounce variable to true. I just fixed that little thing and BOOM! working :smile: I also changed from objectValue to CFrameValue but thats not really too important. bug fixed yipee guys!!

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