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

Why is my Level datastore saving the same as other leaderstats?

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local ds1 = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local stats = Instance.new('IntValue', player)
	stats.Name = 'leaderstats'
	
	local points = Instance.new('IntValue', stats)
	points.Name = 'Money'
	points.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, points.Value)
	points.Changed:connect(function()
		ds:SetAsync(player.UserId, points.Value)
	end)
	game.Players.PlayerRemoving:connect(function(player)
		ds:SetAsync(player.UserId, points.Value)
	end)
	
	local level = Instance.new('IntValue', stats)
	level.Name = 'Level'
	level.Value = ds1:GetAsync(player.UserId) or 0
	ds1:SetAsync(player.UserId, level.Value)
	level.Changed:connect(function()
		ds1:SetAsync(player.UserId, level.Value)
	end)
	game.Players.PlayerRemoving:connect(function(player)
		ds1:SetAsync(player.UserId, level.Value)
	end)



	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			local tag = character.Humanoid:FindFirstChild("creator")
			if tag ~= nil then
				if tag.Value ~= nil then
					points.Value = points.Value + 0
					level.Value = level.Value + 0
					if character.Humanoid:FindFirstChild('creator') then
						local Killer = character.Humanoid.creator.Value
						Killer.leaderstats.Money.Value = Killer.leaderstats.Money.Value + 2
						Killer.leaderstats.Level.Value = Killer.leaderstats.Level.Value + 0.1
					end
				end
			end
		end)
	end)
end)


I am trying to make it so that when you kill someone your level goes up by 0.1, but it's not working, and I think it is saving the 'Level' leaderstat with the same as the money, because the save is saveing and loading my level as the same as my money. I have an item thet you need to be a certain level for, and that is not working either because of this.

1 answer

local ds = DataStore:GetDataStore("CashSaveSystem")
local ds1 = DataStore:GetDataStore("CashSaveSystem")

Your ds and ds1 are the same datastores (CashSaveSystem), that's probably what causes problems. Change the name of the second datastore and it should work.

1 comment

0

That's what I had guessed, but I don't know what to change it to. Do you?

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