Help with Fixing My Code

This Code uses DataStore 2 and gives gold when a player kills another one. The problem is the stats gold isnt showing up and I am not sure if my code has a bug.

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)
2 Likes

Please provide the problem, you literally just said how your script works only. We can help you by telling us what your code should do and what’s the problem/bug.

1 Like

Okay Thanks I added the problem

1 Like

Can you show the error output for a bit of a knowledge about what caused the issue? If there’s no errors it has to do with the module you took.

1 Like

I will do that right now Thanks!

1 Like

What line is causing the error?

Example:

Line 9: Attempt to find index nil

Oh wait: Nevermind, just saw.

Yeah I am not sure why though but normally if it should work it should show the gold stat on the leaderstats in the game but it doesn’t

1 Like

Found the problem.

image

You are missing an end) when you wrote the 2nd function. Hopefully this fixes it.

1 Like

I have that for my orgiginal code though

1 Like

You forgot another one too i think

1 Like

Well, you should put the end) before the last end), the image i sent had a drawing of my word “end)” that is supposed to be there, you could try it.

2 Likes

K I will try right now Thanks!


See now stats shown on there If it was correct it would say Gold

It could be the problem where you used a script that modifies the styles of some core graphical user interface, what script do you think you used to change the styles of the game’s GUIs?

Edit: But once again it wouldn’t be 80% the main issue about that bug that declines the leader statistics.

I do not think so because if I take away the leaderstats for killing script it works

I will show u a pic of what I mean right now

I meant that you might have used some scripts that change the style of the GUIs such as changing the backpack gui, the chat bar, etc.

Edit: Also a side note, i’m not really good at identifying the smallest detail that could’ve caused this problem.