How to create a saving data door

Hi there. I am recently working on a script that a player buys a new level through a door

local Proxy = script.Parent.ProximityPrompt
Proxy.Triggered:Connect(function(player)
if (player.leaderstats.Ruby.Value >= 3) then
player.leaderstats.Ruby.Value = player.leaderstats.Ruby.Value - 3
Proxy.Enabled = false
script.Parent:Destroy()
script.Parent.SurfaceGui:Destroy()
end
end)

This is my script and it works the way I want but I cannot understand how to save this so that if the player joins again he will not have to buy again. Kindly Help :grinning:

Put a number value that save, and when is 0, is because he didnt have that, if is 1 is because he have that (and save the value when buy)

(I said number value instead of bool, because is impossible to save bool values)

I did not get it can you explain it again

1 Like

You’ll need to use the Data Store Service to create save data that checks for whether or not that the player has already gone to that level before.

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

local playerUserID = 505306092 -- placeholder
local playerLevel = 0 -- to check which level the user is on

local setSuccess, errorMessage = pcall(function()
    PlayerProgress:SetAsync(playerUserID, playerLevel)
end)
if not setSuccess then
    warn(errorMessage)
end

This code should help serve as an example, but I’d recommend that you do your own research and remember to add in the check that syncs the player’s level with their saved level when they rejoin.

1 Like

1-make script in ServerScriptService this will create Folder inside player and door value they will
save whene changed

local opend = false
local datastorage = game:GetService("DataStoreService")
local isitopen1 = datastorage:GetDataStore("door")
game.Players.ChildAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Name = "doors"
	Folder.Parent = player
	local door1 = Instance.new("BoolValue")
	door1.Parent = Folder
	door1.Name = "door1"
	door1.Value = isitopen1:GetAsync(player.UserId) or opend
	door1.Changed:connect(function()
		isitopen1:SetAsync(player.UserId, door1.Value)
	end)
end)

2- to get if player door opend or closed use

local opend = player.doors.door1.Value

3- make sure you change door value from script not from Localscript

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	player.doors.door1.Value = true
	end)
2 Likes