Help with zombie leaderstats

I really need help with my leaderStats.

PROBLEM - I’m trying to make a zombie game and I’m trying to figure out how to make it where every time you kill a zombie it will show you how many you and your team killed but none of my scripts will work.

1 Like

Would you mind showing us your scripts?

local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player
local Kills = Instance.new(“StringValue”)
Kills.Value = myDataStore:GetAsync(Player.UserId) or 0
Kills.Name = “Kills”
Kills.Parent = leaderstats

local Deaths = Instance.new("StringValue")
Deaths.Value = myDataStore:GetAsync(Player.UserId) or 0
Deaths.Name = "Deaths"
Deaths.Parent = leaderstats

local killStreak = Instance.new("StringValue")
killStreak.Name = "killStreak"
killStreak.Parent = Player

Player.CharacterAdded:Connect(function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	
	humanoid.Died:Connect(function(died)
		Deaths.Value = Deaths.Value + 1
		killStreak.Value = 0
		local tag = humanoid:FindFirstChild("creator")
		local killer = tag.Value
		if tag and killer then
			killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			killer:FindFirstChild("killstreak").Value = killer:FindFirstChild("killstreak").Value + 1
		end
	end)
end)

end)

game.Players.PlayerRemoving:Connect(function(Player)
myDataStore:SetAsync(Player.UserId, Player.leaderstats.Kills.Value, Player.leaderstats.Deaths.Value)
end)

Since these variables are numbers, you need to create an IntValue instead of a StringValue.

Is the last one the correct one ?

Your code doesn’t work because you are setting a string value to a number. I quoted all the instances where StringValue needs to be replaced by IntValue.

ok i will try that thank you, Do i put my script under ServerScriptService ?

DataStores only work on the server, so yes, you would put this script in ServerScriptService.

in my script i have all kind of red lines, How would i fix that ?

You should be able to hover over the red lines to see what the error is. Copy and paste the error here so I can figure out what might be causing it.

And just in case you are going to test the script, DataStores only work on real games, so you must publish your game first and play it in order for DataStores to work.

local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player
local Kills = Instance.new(“IntValue”)
Kills.Value = myDataStore:GetAsync(Player.UserId) or 0
Kills.Name = “Kills”
Kills.Parent = leaderstats

local Deaths = Instance.new("IntValue")
Deaths.Value = myDataStore:GetAsync(Player.UserId) or 0
Deaths.Name = "Deaths"
Deaths.Parent = leaderstats

local killStreak = Instance.new("IntValue")
killStreak.Name = "killStreak"
killStreak.Parent = Player

Player.CharacterAdded:Connect(function(character)
	local humanoid = character:FindFirstChild("Humanoid")

	humanoid.Died:Connect(function(died)
		Deaths.Value = Deaths.Value + 1
		killStreak.Value = 0
		local tag = humanoid:FindFirstChild("creator")
		local killer = tag.Value
		if tag and killer then
			killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			killer:FindFirstChild("killstreak").Value = killer:FindFirstChild("killstreak").Value + 1
		end
	end)
end)

When you hover over the red line(s), what does it say?

sorry if you cant see that give me just a sec ill zoom in

The quotes were causing the problem, try this, I fixed the quotes.

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Kills = Instance.new("IntValue")
Kills.Value = myDataStore:GetAsync(Player.UserId) or 0
Kills.Name = "Kills"
Kills.Parent = leaderstats

local Deaths = Instance.new("IntValue")
Deaths.Value = myDataStore:GetAsync(Player.UserId) or 0
Deaths.Name = "Deaths"
Deaths.Parent = leaderstats

local killStreak = Instance.new("IntValue")
killStreak.Name = "killStreak"
killStreak.Parent = Player

Player.CharacterAdded:Connect(function(character)
	local humanoid = character:FindFirstChild("Humanoid")

	humanoid.Died:Connect(function(died)
		Deaths.Value = Deaths.Value + 1
		killStreak.Value = 0
		local tag = humanoid:FindFirstChild("creator")
		local killer = tag.Value
		if tag and killer then
			killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			killer:FindFirstChild("killstreak").Value = killer:FindFirstChild("killstreak").Value + 1
		end
	end)
end)

Thank you i will try this in just a sec so when i kill a zombie will the kill count show up of do i need to but a script in the zombie ?

Do you have any code that detects when the player kills the zombie? If so, you do not need any additional scripts.

no i dont all the script i showed you is all i have

ok so i just tested it out the leaderboard wont show up and when i tried to kill the zombie its health bar went down and it took 15 seconds before it died

This has always been my problem I’ve been stuck on this for 2 weeks