I am making a obby using neonbloxes tutorial

so i wrote out everything same as he did but getting a issue where the data is not saving once left and rejoined and the other issue is the respawn when die it is spawning the player to a random spot in the middle of the map where there is no spawn point nor a spawn part but once it does spawn me to a random spot and i reset my character once or twice it then fixes it self but idk how to fix those issues i will post the code under the this post as a reply any help or feed back is appreciated im still learning to script

2 Likes

local Players = game:GetService(“Players”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local SkipStage = ReplicatedStorage:WaitForChild(“SkipStage”)

local Checkpoints = workspace:WaitForChild(“Checkpoints”)
local inGameStartupPlayers = {}
local CurrentStage = {}
local TouchDb = {}

local ProductId = 1371663739

local function NewCharacter(player, char)
local TempCurrentStage = CurrentStage[player.UserId]
if TempCurrentStage ~= nil then
local TempCheckpoint = Checkpoints:FindFirstChild(TempCurrentStage)
if TempCheckpoint ~= nil then
repeat wait(0.1) until char.PrimaryPart ~= nil
char:SetPrimaryPartCFrame(CFrame.new(TempCheckpoint.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, math.rad(TempCheckpoint.Orientation.Y) + math.rad(90), 0))
end
end
end

local function NewPlayer(player)
CurrentStage[player.UserId] = 1

local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Stage = Instance.new("IntValue", leaderstats)
Stage.Name = "Stage"
Stage.Value = 1

local TempChar = player.Character
if TempChar ~= nil then
	NewCharacter(player, TempChar)
end
player.CharacterAdded:Connect(function(char)
	NewCharacter(player, char)
end)

end

Players.PlayerAdded:Connect(function(player)
if inGameStartupPlayers[player] == nil then
NewPlayer(player)
end
end)

Players.PlayerRemoving:Connect(function(player)
CurrentStage[player.UserId] = nil
end)

SkipStage.OnServerInvoke = function(player)
local connection
local leaderstats = player:FindFirstChild(“leaderstats”)
if leaderstats ~= nil then
local Stage = leaderstats:FindFirstChild(“Stage”)
if Stage ~= nil then
if #Checkpoints:GetChildren() ~= Stage.Value then
local PurchaseResult = “Purchase Failed”
connection = MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, purchased)
if player.UserId == userId and productId == ProductId then
if purchased == true then
PurchaseResult = “Success”
end
end
connection:Disconnect()
end)
MarketplaceService:PromptProductPurchase(player, ProductId)
repeat wait(0.1) until connection.Connected == false or Players:GetPlayerByUserId(player.UserId) == nil
return PurchaseResult
else
return “You have reached the highest stage!”
end
end
end
end

MarketplaceService.ProcessReceipt = function(recieptInfo)
if recieptInfo.ProductId == ProductId then
local player = Players:GetPlayerByUserId(recieptInfo.PlayerId)
if player ~= nil then
CurrentStage[player.UserId] = CurrentStage[player.UserId] + 1
local leaderstats = player:FindFirstChild(“leaderstats”)
if leaderstats ~= nil then
local Stage = leaderstats:FindFirstChild(“Stage”)
if Stage ~= nil then
Stage.Value = CurrentStage[player.UserId]
end
end
local TempChar = player.Character
if TempChar ~= nil then
NewCharacter(player, TempChar)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end

for i,v in pairs(Checkpoints:GetChildren()) do
local StageNum = tonumber(v.Name)
v.Touched:Connect(function(hit)
local char = hit.Parent
if char ~= nil then
local Humanoid = char:FindFirstChildOfClass(“Humanoid”)
if Humanoid ~= nil and Humanoid.Health > 0 then
local player = Players:GetPlayerFromCharacter(char)
if player ~= nil and (TouchDb[player.UserId] or 0) + 1 <= os.time() then
TouchDb[player.UserId] = os.time()
local TempCurrentStage = CurrentStage[player.UserId]
if TempCurrentStage == StageNum - 1 then
CurrentStage[player.UserId] = StageNum
local TempLeaderstats = player:FindFirstChild(“leaderstats”)
if TempLeaderstats ~= nil then
local TempStage = TempLeaderstats:FindFirstChild(“Stage”)
if TempStage ~= nil then
TempStage.Value = StageNum
end
end
end
end
end
end
end)
end

inGameStartupPlayers = Players:GetPlayers()
for i,v in pairs(inGameStartupPlayers) do
spawn(function()
NewPlayer(v)
end)
end

inGameStartupPlayers = {}

Hi, the reason for no data is saving, is because you’re not saving data at all. :slight_smile:
Leaderstats is only a temporary way of showing their values in the leaderboard in the playerlist.

3 Likes

is there a way to edit it to make it work becuse ive watched roughly 12 videos on saving data checkpoints and everyone that i have watched wrote the scripts diffrently and then some that only went through a very little bit then stopped and
never finished it

1 Like

Here in this thread I am explaining how you use DataStore2 to save data.

2 Likes

so my question is how come people make tutorial’s and not follow through with it like why take the time to make half of the steps and not kinda keep them updated over time even if its a old vid alot of people who are trying to learn it teaches them but i feel like if someone makes a vid then out of no where they just stop it dont really teach those who are trying to learn if that make sense

1 Like

Haha good question. Making tutorials is hard work and sometimes people just don’t finish what they set out to. It’s not a huge detriment to learners though, because tutorials are really only useful for teaching you the basics and as you learn you’ll need them less and less. The solutions to problems will just magically pop into your head. Or something. IMO you’ll do fine if you follow any tutorials you find and then just ask here on the forum when the tutorials are unfinished, unclear, bad or when there are no tutorials on your exact problem.

Tutorials can only show you “so much”. What you need to understand is, that people making the tutorials are also themself learning while they go. So just because they make a tutorial, does not mean that they’ve actually mastered scripting.

I made a few tutorials a few years ago, and I can tell you that even though my tutorials worked, I only knew 20% of what I know now.

i get planning everything out editing ect but where i come from is more get taught and see if you can make it a little better or not have extra stuff added to it more of compressing it bassicly then teach and see where they go with it. but i only asked becuse i like to learn and i like the interworking of stuff

hey emma
image
is there a way move the ui or how can i make it fit for pc and mobile since i selected the main part but it brings the resize box up which when i drag it or try to resize it makes it seems as if its not centerd

Sorry I don’t know, I don’t use those controls to make GUIs. Feel free to make another post about that, other people might not see your new question since it’s 10 comments down the post.

Go in game settings and make sure roblox api access or whatever is enabled. Also to actually save data, use DataStoreService. Example below

local DataStoreService = game:GetService("DataStoreService")
local ExampleDataStore = DataStoreService:GetDataStore("ExampleDataStore")

-- Store data
ExampleDataStore:SetAsync("ExampleKey", "ExampleValue")

-- Retrieve data
local retrievedData = ExampleDataStore:GetAsync("ExampleKey")
print(retrievedData) -- Output: ExampleValue

Use scale for size not offset
image

is there a certain spot that it goes into as if i took everything from above in the long script to add into it or can i make one near the bottom of the script or will that break it by any chance? i guess im asking if i was to edit the script to add the data store in where would i put it like if i was to add it near the start of the script vs near the end does it make any differences in where its put within the script

like for this example when its wrote out like this i can understand it but when i was looking at what i posted it made kinda no sense since its everything was put together instead of breaking it down nice and neat


if you dont mind me asking from what i took from the example the top part where says local data store and then at my bottom arrow is for what?exactly i thought it was grabbing data for the checkpoints but whats the data store grabbing anything or was it placed to have the player save data added into it at some point

to add on i was thinking about adding like player trails as like a gamepass does that need a datastore of any kind or no since it would be fired event like a skip stage? since its a product

I want to say thank you to everyone for helping me out for the questions i have and thank you for the helpful reply’s which is expanding my knowledge of scripting!