Big problem with Attribute System

Greetings,

So I made an Attribute System,
but the problem is that it seems like when there is another player in my server and I rejoin, the points gets doubled. Clicking the Reset Points button fixes everything.


Reset Button Code :

-- Services

local remote = game:GetService("ReplicatedStorage"):WaitForChild("AttributeRemotes"):WaitForChild("Reset")

----------------------------------------------

-- Variables

local player = game.Players.LocalPlayer

local points = player:WaitForChild("leaderstats"):WaitForChild("Level")

----------------------------------------------

-- Functions

script.Parent.Activated:Connect(function()

script.Parent.Parent:WaitForChild("Attack"):WaitForChild("Value").Text = 0

script.Parent.Parent:WaitForChild("Health"):WaitForChild("Value").Text = 0

script.Parent.Parent:WaitForChild("MaxStamina"):WaitForChild("Value").Text = 0

script.Parent.Parent:WaitForChild("Speed"):WaitForChild("Value").Text = 0

script.Parent.Parent:WaitForChild("Total"):WaitForChild("Value").Text = points.Value

remote:FireServer()

end)

----------------

-- Update

local function UpdateGui()

script.Parent.Parent:WaitForChild("Total"):WaitForChild("Value").Text = points.Value

script.Parent.Parent:WaitForChild("Health"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Health").Value

script.Parent.Parent:WaitForChild("MaxStamina"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("MaximumStamina").Value

script.Parent.Parent:WaitForChild("Speed"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Speed").Value

script.Parent.Parent:WaitForChild("Attack"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Attack").Value

end

UpdateGui()

player.CharacterAdded:Connect(function(character)

wait(3)

UpdateGui()

end)

game.Players.PlayerAdded:Connect(function(player)

wait(3)

UpdateGui()

end)

leaderstats Code :

-- Services

local remote = game:GetService("ReplicatedStorage"):WaitForChild("AttributeRemotes"):WaitForChild("Reset")

----------------------------------------------

-- Variables

local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats"):WaitForChild("Level")

----------------------------------------------

-- Functions

script.Parent.Activated:Connect(function()
	
	script.Parent.Parent:WaitForChild("Attack"):WaitForChild("Value").Text = 0
	script.Parent.Parent:WaitForChild("Health"):WaitForChild("Value").Text = 0
	script.Parent.Parent:WaitForChild("MaxStamina"):WaitForChild("Value").Text = 0
	script.Parent.Parent:WaitForChild("Speed"):WaitForChild("Value").Text = 0
	script.Parent.Parent:WaitForChild("Total"):WaitForChild("Value").Text = points.Value

	remote:FireServer()
end)

----------------

-- Update

local function UpdateGui()
	script.Parent.Parent:WaitForChild("Total"):WaitForChild("Value").Text = points.Value
	script.Parent.Parent:WaitForChild("Health"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Health").Value
	script.Parent.Parent:WaitForChild("MaxStamina"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("MaximumStamina").Value
	script.Parent.Parent:WaitForChild("Speed"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Speed").Value
	script.Parent.Parent:WaitForChild("Attack"):WaitForChild("Value").Text = player:WaitForChild("Attributes"):WaitForChild("Attack").Value
end

UpdateGui()

player.CharacterAdded:Connect(function(character)
	wait(3)
	UpdateGui()
end)

game.Players.PlayerAdded:Connect(function(player)
	wait(3)
	UpdateGui()
end)

Any help is very appreciated!

I don’t think the issue is clientsided, as the server manages the points. Would it be possible to see the code which creates the leaderstats?

Side note: You have a lot of script.Parent and ``player:WaitForChild(“Attributes”), I would recommend creating a variable for any value used more than once. Makes the code more readable.

1 Like

Oops sorry I forgot to change the second code as you can see above.

Here is the leaderstats script.

-- Services

local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local PLRS = game:GetService("Players")
local SSS = game:GetService("ServerScriptService")
local SS = game:GetService("ServerStorage")
local LIGHTNING = game:GetService("Lighting")
local SG = game:GetService("StarterGui")
local SP = game:GetService("StarterPack")

----------------------------------------------

-- DataStore Variables

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
local ToolsDataStore = DataStoreService:GetDataStore("ToolsDataStore")

----------------------------------------------

-- Variables

local TablePrinterModule = require(3148021300)

local Pets = game:GetService("ReplicatedStorage"):WaitForChild("Pets")
local PlayerPets = workspace:WaitForChild("Pets")

----------------------------------------------

-- Attribute Variables

local StarterSpeed = game:GetService("ReplicatedStorage"):WaitForChild("CurrentWalkSpeed").Value
local StarterHealth = 100
local StarterJumpPower = 50
local starterMaxStamina = 100

local spdPerPoint = 0.5
local hpPerPoint = 10
local jumpPowerPerPoint = 1
local maxStaminaPerPoint = 10

local speedCap = 80
local jumpCap = 120

local HealthIncrementPerLevel = 5
local AttributeIncrement = 1

----------------------------------------------

-- Cancel Quest
local remote = game:GetService("ReplicatedStorage"):WaitForChild("QuestRemote")

remote.OnServerEvent:Connect(function(player, val)
	local questInfoF = player:WaitForChild("QuestInformation")
	if val == "CancelQuest" then
		for i, v in pairs(questInfoF:GetChildren()) do
			if v.className == "StringValue" then
				v.Value = "Default"
			elseif v.className == "IntValue" then
				v.Value = 0
			end
		end
	end
end)

----------------------------------------------------------------------------------------------

game.Players.PlayerAdded:Connect(function(player)
	
	-- Music
	player.PlayerGui:WaitForChild("GameMusic"):Play()

	-----------------
	
	-- Variables
	
	local playerID = player.UserId
	local character = player.Character
	local playerGui = player.PlayerGui
	
	-----------------
	
	-- Functions
	
	--[[    local function LoadPet(petValue)
		wait(6)
		if petValue.Value ~= "" then
			if Pets:FindFirstChild(petValue.Value) then
				local pet = Pets:FindFirstChild(petValue.Value):Clone()
				local petPosition = playerGui:WaitForChild("PetShop"):WaitForChild("Frame"):WaitForChild("ScrollingFrame"):FindFirstChild(petValue.Value):FindFirstChild("Buy"):FindFirstChild("PetPosition").Value
				pet.Name = player.Name
				pet.Parent = PlayerPets
				local function Follow(pet)
					local MovementAnimationTrack = pet:FindFirstChild("AnimationController"):FindFirstChild("Animator"):LoadAnimation(pet:FindFirstChild("Animations"):FindFirstChild("Movement"))
					local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
					local BodyPosition = Instance.new("BodyPosition", pet:WaitForChild("Pet"))
					BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
					local BodyGyro = Instance.new("BodyGyro", pet:WaitForChild("Pet"))
					BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
					character.Humanoid.Running:Connect(function(speed)
						if speed > 0 then
							MovementAnimationTrack:Play()
							MovementAnimationTrack:AdjustSpeed(3)
						end
						if speed <= 0 then
							MovementAnimationTrack:Stop()
							MovementAnimationTrack.TimePosition = 0
						end
					end)
					while wait() do
						BodyPosition.Position = HumanoidRootPart.Position + petPosition
						BodyGyro.CFrame = HumanoidRootPart.CFrame
						pet:WaitForChild("Pet").Orientation = HumanoidRootPart.Orientation + Vector3.new(0,180,0)
					end
				end
				Follow(pet)
			end
		end
	end ]]
	
	-----------------
		
	-- Folders
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local weapon = Instance.new("Folder", player)
	weapon.Name = "Weapon"
	
	local attacks = Instance.new("Folder", weapon)
	attacks.Name = "WeaponAttacks"

	local projectiles = Instance.new("IntValue", leaderstats)
	projectiles.Name = "Projectiles"
	projectiles.Value = 0

	local currentProjectile = Instance.new("StringValue", leaderstats)
	currentProjectile.Name = "CurrentProjectile"
	currentProjectile.Value = "Shuriken"

	local QuestInformation = Instance.new("Folder", player)
	QuestInformation.Name = "QuestInformation"
	
	local attributes = Instance.new("Folder")
	attributes.Name = "Attributes"
	attributes.Parent = player
	
	local petBoostMultiplier = Instance.new("NumberValue", player)
	petBoostMultiplier.Name = "PetBoostMultiplier"
	petBoostMultiplier.Value = 1

	local hasReadTheTutorial = Instance.new("BoolValue", player)
	hasReadTheTutorial.Name = "HasReadTheTutorial"
	hasReadTheTutorial.Value = false

	local customizedCharacter = Instance.new("BoolValue", player)
	customizedCharacter.Name = "CustomizedCharacter"
	customizedCharacter.Value = false
	
	local loadingScreen = Instance.new("BoolValue", player)
	loadingScreen.Name = "LoadingScreen"
	loadingScreen.Value = false
	
	local ownsHouse = Instance.new("BoolValue", player)
	ownsHouse.Name = "OwnsHouse"
	ownsHouse.Value = false
	
	-----------------
	
	-- leaderstats
	local yen = Instance.new("IntValue", leaderstats)
	yen.Name = "Yen"
	
	local soulPoints = Instance.new("IntValue", leaderstats)
	soulPoints.Name = "Souls"

	local Level = Instance.new("IntValue", leaderstats)
	Level.Name = "Level"
	Level.Value = 1
	
	local XP = Instance.new("IntValue", leaderstats)
	XP.Name = "XP"
	XP.Value = 0
	
	local MaxXP = Instance.new("IntValue", leaderstats)
	MaxXP.Name = "MaxXP"
	MaxXP.Value = 100
	
	local rebirths = Instance.new("IntValue", leaderstats)
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	
	local rebirthTokens = Instance.new("IntValue", leaderstats)
	rebirthTokens.Name = "RebirthTokens"
	rebirthTokens.Value = 0
	
	local rebirthYenBoost = Instance.new("IntValue", leaderstats)
	rebirthYenBoost.Name = "RebirthYenBoost"
	rebirthYenBoost.Value = 1
	
	local stamina = Instance.new("IntValue", leaderstats)
	stamina.Name = "Stamina"
	stamina.Value = 100
	
	local maxStamina = Instance.new("IntValue", stamina)
	maxStamina.Name = "MaxStamina"
	maxStamina.Value = 100
	
	local timePlayed = Instance.new("IntValue", leaderstats)
	timePlayed.Name = "Time Played"
	timePlayed.Value = 0
	
	local pet = Instance.new("StringValue", leaderstats)
	pet.Name = "Pet"
	pet.Value = ""
	-- LoadPet(pet)
	
	-----------------

	-- Achievements
	local achievements = Instance.new("Folder", player)
	achievements.Name = "Achievements"
	
	local goldenShurikens = Instance.new("IntValue", achievements)
	goldenShurikens.Name = "GoldenShurikens"
	goldenShurikens.Value = 0
	
	-----------------
	
	-- Weapon
	local currentWeapon = Instance.new("StringValue", weapon)
	currentWeapon.Name = "CurrentWeapon"
	currentWeapon.Value = ""
	
	----------------
	
	-- QuestInfo
	local Title = Instance.new("StringValue", QuestInformation)
	Title.Name = "QuestTitle"
	Title.Value = "Default"

	local Task = Instance.new("StringValue", QuestInformation)
	Task.Name = "QuestTask"
	Task.Value = "Default"

	local Objective = Instance.new("IntValue", QuestInformation)
	Objective.Name = "QuestObjective"
	Objective.Value = 0

	local Progress = Instance.new("IntValue", QuestInformation)
	Progress.Name = "QuestProgress"
	Progress.Value = 0

	local Reward = Instance.new("IntValue", QuestInformation)
	Reward.Name = "QuestReward"
	Reward.Value = 0

	local Reward2 = Instance.new("IntValue", QuestInformation)
	Reward2.Name = "QuestReward2"
	Reward2.Value = 0
	
	-----------------
	
	-- IsUsingAttack Values
	local IsUsingAttack1 = Instance.new("BoolValue", attacks)
	IsUsingAttack1.Name = "IsUsingAttack1"
	IsUsingAttack1.Value = false
	
	local IsUsingAttack2 = Instance.new("BoolValue", attacks)
	IsUsingAttack2.Name = "IsUsingAttack2"
	IsUsingAttack2.Value = false
	
	local IsUsingAttack3 = Instance.new("BoolValue", attacks)
	IsUsingAttack3.Name = "IsUsingAttack3"
	IsUsingAttack3.Value = false
	
	local IsUsingAttack4 = Instance.new("BoolValue", attacks)
	IsUsingAttack4.Name = "IsUsingAttack4"
	IsUsingAttack4.Value = false
	
	local IsUsingAttack5 = Instance.new("BoolValue", attacks)
	IsUsingAttack5.Name = "IsUsingAttack5"
	IsUsingAttack5.Value = false
	
	local IsUsingAttack6 = Instance.new("BoolValue", attacks)
	IsUsingAttack6.Name = "IsUsingAttack6"
	IsUsingAttack6.Value = false

	local IsUsingAttack7 = Instance.new("BoolValue", attacks)
	IsUsingAttack7.Name = "IsUsingAttack7"
	IsUsingAttack7.Value = false

	-----------------
	
	-- Attributes
	local health = Instance.new("IntValue")
	health.Name = "Health"
	health.Parent = attributes
	
	local attack = Instance.new("IntValue")
	attack.Name = "Attack"
	attack.Parent = attributes
	
	local speed = Instance.new("IntValue")
	speed.Name = "Speed"
	speed.Parent = attributes
	
	local maximumStamina = Instance.new("IntValue")
	maximumStamina.Name = "MaximumStamina"
	maximumStamina.Parent = attributes
	
	-----------------
	
	-- Player's Weapon Names
	
	local WeaponNames = Instance.new("Folder", player)
	WeaponNames.Name = "WeaponNames"
	
	-----------------
	
	-- Gamepasses
	
	local Gamepasses = Instance.new("Folder")
	Gamepasses.Name = "Gamepasses"
	Gamepasses.Parent = player
	
	local InventorySlots = Instance.new("IntValue")
	InventorySlots.Name = "InventorySlots"
	InventorySlots.Parent = Gamepasses
	InventorySlots.Value = 3
	
	-----------------
	
	-- Avatar
	
	local Avatar = Instance.new("Folder")
	Avatar.Parent = player
	Avatar.Name = "Avatar"
	
	local Hair = Instance.new("StringValue")
	Hair.Parent = Avatar
	Hair.Name = "Hair"
	
	-----------------
	
	-- Formulas
	
	local RealHP = StarterHealth + (Level.Value * HealthIncrementPerLevel) + (health.Value * hpPerPoint)
	
	-----------------
	
	-- Level Up

	XP:GetPropertyChangedSignal('Value'):Connect(function()
		repeat
			if XP.Value >= MaxXP.Value then
				Level.Value += 1
				XP.Value -= MaxXP.Value
				MaxXP.Value *= 1.25
				character.Humanoid.MaxHealth += HealthIncrementPerLevel
			end
		until XP.Value < MaxXP.Value
	end)
	
	------------
	
	-- Health
	
	local function SetupHealth(character)
		local humanoid = character.Humanoid
		humanoid.MaxHealth = RealHP
		wait(0.25)
		humanoid.Health = humanoid.MaxHealth
	end

	local function SetupSpeed(character)
		local humanoid = character.Humanoid
		humanoid.WalkSpeed = StarterSpeed + speed.Value
	end
	
	SetupSpeed(character)
	
	player.CharacterAdded:Connect(SetupSpeed)
	player.CharacterAdded:Connect(SetupHealth)
	
	-----------------

	-- Attribute Points

	local HealthRemote = RS:WaitForChild("AttributeRemotes"):WaitForChild("AddHealth")
	local SpeedRemote = RS:WaitForChild("AttributeRemotes"):WaitForChild("AddSpeed")
	local AttackRemote = RS:WaitForChild("AttributeRemotes"):WaitForChild("AddAttack")
	local MaxStaminaRemote = RS:WaitForChild("AttributeRemotes"):WaitForChild("AddMaxStamina")
	local ResetRemote = RS:WaitForChild("AttributeRemotes"):WaitForChild("Reset")


	local function PointsAvailable(player)
		local PointsUsed = player.Attributes.Health.Value + player.Attributes.Speed.Value + player.Attributes.Attack.Value + player.Attributes.MaxStamina.Value
		local PointsAvailable = player.leaderstats.Level.Value - PointsUsed
		return PointsAvailable > 0
	end

	HealthRemote.OnServerEvent:Connect(function(player)
		player.Attributes.Health.Value += AttributeIncrement
		player.Character.Humanoid.MaxHealth = RealHP
		player.Character.Humanoid.Health = RealHP
	end)

	SpeedRemote.OnServerEvent:Connect(function(player)
		if player.Attributes.Speed.Value < speedCap then
			player.Attributes.Speed.Value += AttributeIncrement
			player.Character.Humanoid.WalkSpeed = StarterSpeed + player.Attributes.Speed.Value * spdPerPoint
		end
	end)

	AttackRemote.OnServerEvent:Connect(function(player)
		player.Attributes.Attack.Value += AttributeIncrement
	end)

	MaxStaminaRemote.OnServerEvent:Connect(function(player)
		player.Attributes.MaximumStamina.Value += AttributeIncrement
		player.leaderstats.Stamina.MaxStamina.Value += maxStaminaPerPoint
	end)

	ResetRemote.OnServerEvent:Connect(function(player)
		player.Attributes.Health.Value = 0
		player.Attributes.Attack.Value = 0
		player.Attributes.Speed.Value = 0
		player.Attributes.MaximumStamina.Value = 0
		player.Character.Humanoid.MaxHealth = RealHP
		player.Character.Humanoid.Health = RealHP
		player.Character.Humanoid.WalkSpeed = (StarterSpeed + player.Attributes.Speed.Value * spdPerPoint)
		maxStamina.Value = starterMaxStamina
	end)
	
	-----------------
	
	-- Quest Reward
	local rewarded = false

	Title.Changed:Connect(function()
			Progress.Changed:Connect(function()
			if Progress.Value >= Objective.Value and rewarded == false then
				rewarded = true
				local function GiveReward()
					player:WaitForChild("leaderstats"):WaitForChild("Yen").Value += Reward.Value
					player:WaitForChild("leaderstats"):WaitForChild("XP").Value += Reward2.Value
					Title.Value = "Default"
					Task.Value = "Default"
					Progress.Value = 0
					Objective.Value = 0
					Reward.Value = 0
					Reward2.Value = 0
					player:WaitForChild("PlayerGui"):WaitForChild("Notifications"):WaitForChild("CompletedQuest").Visible = true
					wait(2)
					player:WaitForChild("PlayerGui"):WaitForChild("Notifications"):WaitForChild("CompletedQuest").Visible = false
				end
				GiveReward()
				wait(0.001)
				remote:FireClient(player, "CancelQuest")
				wait(0.5)
				rewarded = false
			end
		end)
	end)
	
	-----------------

	-- DataStore

	local data

	local Success, ErrorMessage = pcall(function()
		data = DataStore:GetAsync(playerID)
	end)

	if Success then
		player.leaderstats.Yen.Value = data.Yen -- Saves
		player.leaderstats.Souls.Value = data.Souls -- Saves
		player.leaderstats.Level.Value = data.Level -- Saves
		player.leaderstats.Rebirths.Value = data.Rebirths -- Saves
		player.leaderstats.RebirthTokens.Value = data.RebirthTokens -- Saves
		player.leaderstats.RebirthYenBoost.Value = data.RebirthYenBoost -- Saves
		player.PetBoostMultiplier.Value = data.PetBoostMultiplier -- Saves
		player.leaderstats["Time Played"].Value = data.TimePlayed -- Saves
		
		player.Achievements.GoldenShurikens.Value = data.GoldenShurikens -- Saves
		
		player.Attributes.Health.Value = data.Health -- Saves
		player.Attributes.Speed.Value = data.Speed -- Saves
		player.Attributes.Attack.Value = data.Attack -- Saves
		player.Attributes.MaximumStamina.Value = data.MaximumStamina -- Saves
		
		player.Weapon.CurrentWeapon.Value = data.CurrentWeapon -- Saves
		
		player.leaderstats.Pet.Value = data.Pet -- Saves
		
		player.OwnsHouse.Value = data.House -- Saves
		
		player.Avatar.Hair.Value = data.Hair -- Saves
		
		player.leaderstats.Projectiles.Value = data.Projectiles -- Saves
		player.leaderstats.CurrentProjectile.Value = data.CurrentProjectile -- Saves
		
		player.Gamepasses.InventorySlots.Value = data.InventorySlots
		
		player.QuestInformation.QuestTitle.Value = data.QuestTitle -- Saves
		player.QuestInformation.QuestTask.Value = data.QuestTask -- Saves
		player.QuestInformation.QuestObjective.Value = data.QuestObjective -- Saves
		player.QuestInformation.QuestProgress.Value = data.QuestProgress -- Saves
		player.QuestInformation.QuestReward.Value = data.QuestReward -- Saves
		player.QuestInformation.QuestReward2.Value = data.QuestReward2 -- Saves
		
		player.CustomizedCharacter.Value = data.CustomizedCharacter -- Saves
		player.HasReadTheTutorial.Value = data.HasReadTheTutorial -- Saves
		
		player.leaderstats.MaxXP.Value = data.MaxXP
		player.leaderstats.XP.Value = data.XP
	else
		print("An error has occured whilst loading your data.")
		warn(ErrorMessage)
	end
	
	local ToolData = ToolsDataStore:GetAsync(player.UserId)
	local WeaponsFolder = game:GetService("ServerStorage"):WaitForChild("Weapons")
		
	if ToolData then
		for i, tool in pairs(ToolData) do
			local FolderName = tool:FindFirstChild("SaveToolSystem").FolderName.Value
			local ClonedTool = WeaponsFolder:FindFirstChild(FolderName):FindFirstChild(tool):Clone()
			ClonedTool.Parent = player.Backpack
		end
	end
end)

-------------------------------------------------------------------

-- Save Player's Data

game.Players.PlayerRemoving:Connect(function(player)
	
	local Data = {
		Yen = player.leaderstats.Yen.Value, -- Saves
		Souls = player.leaderstats.Souls.Value, -- Saves
		Level = player.leaderstats.Level.Value, -- Saves
		Rebirths = player.leaderstats.Rebirths.Value, -- Saves
		RebirthTokens = player.leaderstats.RebirthTokens.Value, -- Saves
		RebirthYenBoost = player.leaderstats.RebirthYenBoost.Value, -- Saves
		PetBoostMultiplier = player.PetBoostMultiplier.Value, -- Saves
		TimePlayed = player.leaderstats["Time Played"].Value, -- Saves
		
		GoldenShurikens = player.Achievements.GoldenShurikens.Value, -- Saves
		
		Health = player.Attributes.Health.Value, -- Saves
		Speed = player.Attributes.Speed.Value, -- Saves
		Attack = player.Attributes.Attack.Value, -- Saves
		MaximumStamina = player.Attributes.MaximumStamina.Value, -- Saves
		
		CurrentWeapon = player.Weapon.CurrentWeapon.Value, -- Saves
		
		Pet = player.leaderstats.Pet.Value, -- Saves
		
		House = player.OwnsHouse.Value, -- Saves
		
		Hair = player.Avatar.Hair.Value, -- Saves
		
		Projectiles = player.leaderstats.Projectiles.Value, -- Saves
		CurrentProjectile = player.leaderstats.CurrentProjectile.Value, -- Saves
		
		InventorySlots = player.Gamepasses.InventorySlots.Value,
		
		QuestTitle = player.QuestInformation.QuestTitle.Value, -- Saves
		QuestTask = player.QuestInformation.QuestTask.Value, -- Saves
		QuestObjective = player.QuestInformation.QuestObjective.Value, -- Saves
		QuestProgress = player.QuestInformation.QuestProgress.Value, -- Saves
		QuestReward = player.QuestInformation.QuestReward.Value, -- Saves
		QuestReward2 = player.QuestInformation.QuestReward2.Value, -- Saves
		
		CustomizedCharacter = player.CustomizedCharacter.Value, -- Saves
		HasReadTheTutorial = player.HasReadTheTutorial.Value, -- Saves
		
		MaxXP = player.leaderstats.MaxXP.Value,
		XP = player.leaderstats.XP.Value
	}

	local ToolsData = {}
	
--[[	for i, tool in pairs(player.Character:GetChildren()) do
		if tool:IsA("Tool") then
			table.insert(ToolsData, tool.Name)
		end
	end

	for i, tool in pairs(player.Backpack:GetChildren()) do
		if tool:IsA("Tool") then
			table.insert(ToolsData, tool.Name)
		end
	end			]]

	local Success, ErrorMessage = pcall(function()
		DataStore:SetAsync(player.UserId, Data)
		ToolsDataStore:SetAsync(player.UserId, ToolsData)
	end)

	if Success then
		print("Data successfully saved!")
		-- print(TablePrinterModule(Data))
	else
		print("An error has occured whilst loading your data.")
		warn(ErrorMessage)
	end
	
end)

------------

-- DataStore in-studio

game:BindToClose(function()
	if game:GetService('RunService'):IsStudio() then
		wait(2)
	end
end)

-------------------------------------------------------------------

-- Load House

local function LoadHouse(player)
	wait(4)
	local remote = SG:WaitForChild("HouseSystem"):WaitForChild("LoadHouseRemote")
	remote:FireAllClients()
end

PLRS.PlayerAdded:Connect(LoadHouse)

-------------------------------------------------------------------

-- Load Accessories

local function LoadAccessories(player)
	wait(4)
	for i, values in pairs(player.Avatar:GetChildren()) do
		if values.Value ~= "" then
			RS:FindFirstChild(values.Name.."s"):FindFirstChild(values.Value):Clone().Parent = player.Character
		end
	end
end

PLRS.PlayerAdded:Connect(LoadAccessories)

I don’t see any issue from quickly reading through it, have you tried adding in prints when you are loading / storing the data? Might provide some useful insight as to where the issue is.

Also:
This might be helpful, consider using this (Instance Attributes (roblox.com)) instead of NumberValue (roblox.com) etc. Attributes are faster and more efficient.

1 Like