Scripting Problem

This is my DataStore 2, but it is not working, and I am not sure what I did wrong. Please help! It is supposed to save the gold and update and give money when you kill another player.

game.Players.PlayerAdded:Connect(function(plr)
	local dataGold = DataStore2("Gold", plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"
	
	local gold = Instance.new("IntValue", folder)
	gold.Name = "Gold"
	local initialGold = 100
	gold.Value = dataGold:Get(initialGold)
	
	gold.Changed:Connect(function()
		dataGold:Set(gold.Value)
		
	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
						
				local stats = tag.Value:WaitForChild("leaderstats")
						
				stats["Gold"].Value = stats ["Gold"].Value + 150
						
				end
			end
		end)

Can you fix your script and then send us the details.
Because I cant see what’s dataGold or anything.

Okay I fixed the script Thanks for reminding me!

Did you define what’s DataStore2 is?
You have to download the DataStore2 module in order to use DataStore2.

Example Code :

local DataStore2 = require(game.ServerScriptStorage.DataStore2*)
local dataGold = DataStore2("Gold", plr)

" * ": I prefer putting the module script to ServerScriptStorage but you can put it somewhere else.

Oh sorry I did the wrong code I think, but this doesn’t work still.

local DataStore2 = require(1936396537)

DataStore2.Combine("MasterKey","Gold")

game.Players.PlayerAdded:Connect(function(plr)
	local dataGold = DataStore2("Gold", plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"
	
	local gold = Instance.new("IntValue", folder)
	gold.Name = "Gold"
	
	local initialGold = 100
	gold.Value = dataGold:Get(initialGold)
	
	gold.Changed:Connect(function()
		dataGold:Set(gold.Value)
		
		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
						
						local stats = tag.Value:WaitForChild("leaderstats")
						
						stats["Gold"].Value = stats ["Gold"].Value + 150
						
					end
				end
			end)

Why use creator inside of the character’s humanoid, (Assuming it’s not being found due to the event firing right when the player dies), when you could just use game.Players:GetPlayerFromCharacter?

But my script right now doesnt even Work yet why is that? Is theee a problem still with it besides design?

King_Deadly has a point, just noticed that you were looking for the creator inside the humanoid, you can just store it somewhere in the characters or anywhere in the player, for example:

image

Don’t forget you can also use the humanoid function, died and use it so when that player dies the killer gets gold.

Don’t also forget to add a script where you’ll change the killed user’s stringvalue inside the kill script for a weapon so you’d have the kill and you’ll get money.

Correct the example image i made, i meant “stringvalue” not “numbervalue”.

Also inquistor, i just told you earlier that you’re missing the last end) to close the function.

Okay Thanks let me try it right now!