Obby spawn issue

Hello fellow developers! I am a newbie scripter and i need your help. I made an obby game, its basically a normal obby game but you can go back and forward with arrows. My problem is sometimes when you die it spawns you in the same exact spot. So if you die you are supposed to be at the checkpoint you just died at, but sometimes i get spawned on the spawn island in the exact same spot. Anybody may know what the issue is?


This is where it spawns me sometimes, exactly at this point, but its supposed to spawn you at the checkpoint.

Perhaps share the code and (if applicable) the error code displayed in the console? It will help us assist you faster.

The code for the checkpoints?

No errors in console.

As @Schedency said, some code would be helpful.
Perhaps your respawn script does not wait long enough before TPing you to your checkpoint and you hadn’t been teleported to the original spawn pad yet. If your obby uses spawn pads, make sure the script is setting your player’s respawn location to their current stage.

Yes, the code for the checkpoints, please.

1 Like

local skipId = 1387293989

local dataStoreService = game:GetService(“DataStoreService”)
local mps = game:GetService(“MarketplaceService”)

local stageDataStore = dataStoreService:GetDataStore(“stageStore”)

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"

local stage = Instance.new("IntValue")
stage.Parent = leaderstats
stage.Name = "Stage"
stage.Value = 1

local data

local success, errormessage = pcall(function()
	data = stageDataStore:GetAsync(plr.UserId.. "-Stage")
end)

if success then
	print(tostring(plr).. "'s data was successfully retrieved.")
	stage.Value = data
	
	if stage.Value == 0 then
		stage.Value = 1
		repeat wait() until plr:FindFirstChild("TempStage")
		plr.TempStage.Value = 1
		plr:LoadCharacter()
	end
elseif errormessage then
	warn(tostring(plr).. "'s data had an issue loading.")
	warn(errormessage)
	stage.Value = 1
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
print(tostring(plr)
 " is leaving the game.")

local success, errormessage = pcall(function()
	stageDataStore:SetAsync(plr.UserId.. "-Stage", plr.leaderstats.Stage.Value)
end)

if success then
	print(tostring(plr).. "'s data was successfully saved.")
elseif errormessage then
	warn(tostring(plr).. "'s data had an issue saving.")
	warn(errormessage)
end

end)

mps.ProcessReceipt = function(info)
local plr = game.Players:GetPlayerByUserId(info.PlayerId)
if info.ProductId == skipId then
plr.leaderstats.Stage.Value += 1
plr:LoadCharacter()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end

This doesn’t go over the stage value being changed other than when you are loading the data. Where is it changed when someone steps on the checkpoint?
Are the checkpoints regular parts or are they spawn pads?

Just a side note, I suggest that you do not mark all product purchases as granted even if they were not. Make sure you confirm that the player was there to receive their purchase before returning Enum.ProductPurchaseDecision.PurchaseGranted.

1 Like

game.Players.PlayerAdded:Connect(function(plr)
repeat wait() until plr.leaderstats
local tempStage = Instance.new(“IntValue”)
tempStage.Parent = plr
tempStage.Name = “tempStage”
tempStage.Value = plr.leaderstats.Stage.Value
print(tempStage.Value)

if tempStage.Value == 0 then
	tempStage.Value = 1
end

end)

Why have you created the tempStage value?

For the leaderstats value. So when you complete a stage it shows you “Stage 2”

Yes, but what is tempStage for? You already have a value inside the leaderstats called Stage.
I would also like to note that unless you have sent an incomplete script, tempStage will only ever be its first value. Is tempStage used anywhere?

I really dont know, i watched a tutorial about it and i just wrote what it said.

Well, it is quite difficult to help you when I am only seeing parts of scripts and half-formatted code.

Also, you might be getting an error if the player has no saved data here. I suggest you add a check to see if it is nil or not.

Altered code:

print(tostring(plr).. "'s data was successfully retrieved.")
	stage.Value = data or 0
	
	if stage.Value == 0 then
		stage.Value = 1
		repeat wait() until plr:FindFirstChild("TempStage")
		plr.TempStage.Value = 1
		plr:LoadCharacter()
	end

Well then could you check out the game to see for any problems?

I see no point in joining, as that will not show me the code.
If you want some support on this, I suggest you start by correctly using the code blocks to format your code.
Have you seen any error messages in the console?

Ingame console or in roblox studio?

Both. Make sure you are checking on the server tab when you are in-game.

this is the ingame console, it has no problems.

Do you know where the script is that teleports you when you spawn?

I have checkpoints: 1,2,3,4,5,6
 And there is a script in all of them, shall i send that?