Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help With Saving Levels and Experience?

So basically I have made a script to save cash for the game, however I am trying to make different scripts of the same thing to save them. It is not working on anything I do and I need help on how to save all three things in just one script so I can use them under a Data category instead of leaderstats so there is no leaderboard. Thanks!

I would like to use something under my knowledge to

Here are the scripts.

SAVE CASH

local DSService = game:GetService('DataStoreService'):GetDataStore('Cash')
game.Players.PlayerAdded:connect(function(plr)
	-- Define variables
	local uniquekey = 'id-'..plr.userId
	local leaderstats = Instance.new('IntValue', plr)
	local savevalue =  Instance.new('IntValue')
	leaderstats.Name = 'leaderstats3'
	savevalue.Parent = leaderstats
	savevalue.Name = 'Cash'
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats3.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)	
	
	
end)

*HAVE LEVEL AND XP *

game.Players.PlayerAdded:connect(function(Player) ----- When a Player joins a server this function happens
	local Data = Instance.new("IntValue",Player) ----Makes an IntValue inside Player
	Data.Name = "Data" -----It's name is Data ([Note]: You could change it to leaderstats if you would like a leaderboard with it.)
	local XP = Instance.new("IntValue",Data) ----Makes a IntValue inside Data
	XP.Name = "XP" 
	XP.Value = 0
	local Level = Instance.new("IntValue",Data) ------- Makes an IntValue Inside Data
	Level.Name = "Level" ------- It's name is Level
	Level.Value = 1 
	local Tries = Instance.new("IntValue",Data)
	Tries.Value = 10
	Tries.Name = "Tries"
	
	XP.Changed:connect(function() XPChange(Player,XP,Level) end) ---- To change the XP, XPChanged function occours
	
end)

function XPChange(Player,XP,Level) ------ XPChanged function
	if XP.Value >= Level.Value*150  then ----- this function occours happens if the Level's Value is greater or equal to this 150 ([Note]: Change 150 to the max XP)
		XP.Value = 0 --- Resets the XP
		Level.Value = Level.Value+ 1
	end
end

Thanks! Also remember I need help scripting something like the first script, but saving all three things.

4 comments

0

Oh, your an AlvinBlox fan. Most of his vids are outdated

0

Don't really understand what your question is? Do you want to combine them all or something else?

0

I want to combine them all into one script that saves them.

0

Observe what each part of the script does, since Lua is kinda self-explainatory when u see it.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.