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

How would I reset/make a new datastore on this script?

I forgot how to, I haven't done it in awhile.

local DataStore = game:GetService("DataStoreService")
local Levels = DataStore:GetDataStore("Levels")
local XP = DataStore:GetDataStore("XP")
local FrenzyCoins = DataStore:GetDataStore("FrenzyCoins")
local XPGoal = DataStore:GetDataStore("XPGOAL")

game.Players.PlayerAdded:Connect(function(plr)
	local PlayerCurrency = Instance.new("Folder")
	PlayerCurrency.Name = "PlayerCurrency"
	PlayerCurrency.Parent = plr
	
	local PlayerLevel = Instance.new("Folder")
	PlayerLevel.Name = "PlayerLevel"
	PlayerLevel.Parent = plr
	
	local PrimalPoints = Instance.new("IntValue")
	PrimalPoints.Name = "Primal Points"
	PrimalPoints.Value = 0
	PrimalPoints.Parent = PlayerCurrency
	
	local FrenzyCoin = Instance.new("IntValue")
	FrenzyCoin.Name = "Frenzy Coins"
	FrenzyCoin.Value = FrenzyCoins:GetAsync(tostring(plr.UserId)) or 0
	FrenzyCoin.Parent = PlayerCurrency

	
	local Experience = Instance.new("IntValue")
	Experience.Name = "XP"
	Experience.Value = XP:GetAsync(tostring(plr.UserId)) or 0
	Experience.Parent = PlayerLevel
	
	
	local Level = Instance.new("IntValue")
	Level.Name = "Level"
	Level.Value = Levels:GetAsync(tostring(plr.UserId)) or 1
	Level.Parent = PlayerLevel

	
	local ExperienceGoal = Instance.new("IntValue")
	ExperienceGoal.Name = "ExperienceGoal"
	ExperienceGoal.Value = XPGoal:GetAsync(tostring(plr.UserId)) or 100
	ExperienceGoal.Parent = PlayerLevel

	
	Experience.Changed:Connect(function()
		if plr.PlayerLevel:WaitForChild("XP").Value >= plr.PlayerLevel:WaitForChild("ExperienceGoal").Value then
			print("Saving")
			Level.Value = Level.Value + 1
			ExperienceGoal.Value = ExperienceGoal.Value + 100
			Levels:SetAsync(plr.UserId, Level.Value)
			XP:SetAsync(plr.UserId, Experience.Value)
			XPGoal:SetAsync(plr.UserId, ExperienceGoal.Value)	
			FrenzyCoins:SetAsync(plr.UserId, FrenzyCoin.Value)
			print("Saved")
		else
			Levels:SetAsync(plr.UserId, Level.Value)
			XP:SetAsync(plr.UserId, Experience.Value)
			XPGoal:SetAsync(plr.UserId, ExperienceGoal.Value)	
			FrenzyCoins:SetAsync(plr.UserId, FrenzyCoin.Value)
			print("Saved")
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Levels:SetAsync(plr.UserId, plr.PlayerLevel.Level.Value)
	XP:SetAsync(plr.UserId, plr.PlayerLevel.Experience.Value)
	XPGoal:SetAsync(plr.UserId, plr.PlayerLevel.ExperienceGoal.Value)	
	FrenzyCoins:SetAsync(plr.UserId, plr.PlayerCurrency["Frenzy Coin"].Value)
end)


1 answer

Erm very simple but why the hell have you cluttered this script up so much. You are instantly going to break ur saving limits. Try doing something like this

local datastore = game:GetService("DataStoreService"):GetDataStore("statstorage")

game.Players.PlayerAdded:connect(function(player)
	
	local folder = Instance.new("Folder", player)
	folder.Name = "Information"

	local currency = Instance.new("Folder", folder)
	currency.Name = "PlayerCurrency"

	local levels = Instance.new("Folder", folder)
	levels.Name = "PlayerLevel"
	
	local primalpoints = Instance.new("IntValue", currency)
	primalpoints.Name = "Primal Points"
	primalpoints.Value = 0

	local frenzycoin = Instance.new("IntValue", currency)
	frenzycoin.Name = "Frenzy Coins"

	local Experience = Instance.new("IntValue", levels)
	Experience.Name = "XP"

	local Level = Instance.new("IntValue", levels)
	Level.Name = "Level"

	local ExperienceGoal = Instance.new("IntValue", levels)
	ExperienceGoal.Name = "ExperienceGoal"

	local key = "player-"..player.userId
	
	local savedValues = datastore:GetAsync(key)
	
	if savedValues then
		primalpoints.Value = savedValues[1]
		frenzycoin.Value = savedValues[2]
		Experience.Value = savedValues[3]
		Level.Value = savedValues[4]
		ExperienceGoal.Value = savedValues[5]
	else
	local valuesToSave = {primalpoints.Value, frenzycoin.Value, Experience.Value, Level.Value, ExperienceGoal.Value}
	datastore:SetAsync(key, valuesToSave)
	end
	
end)


game.Players.PlayerRemoving:connect(function(player)
	
	local key = "player-"..player.userId
	
	local valuesToSave = {player.Information.PlayerCurrency["Primal Points"].Value, player.Information.PlayerCurrency["Frenzy Coins"].Value, player.Information.PlayerLevel.XP.Value, player.Information.PlayerLevel.Level.Value, player.Information.PlayerLevel.ExperienceGoal.Value}
	datastore:SetAsync(key, valuesToSave)
end)

I just sat here for 20 minutes making a entire new datastore saving system. For you. Hope you actualy use it. This only saves the stats once instead of multiple times so you don't break the saving limit ( aka it saves a table instead of all the values induvidualy )

2 comments

0

Dude, thanks so much. Can't tell you how much I appreciate this.

0

perhaps pick my comment as the answer

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