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?
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.
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.
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?
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
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?