Leaderstats support

Try reviewing this script:

local dataStoreService = game:GetService("DataStoreService")
local killSave = dataStoreService:GetDataStore("PlayerKills")

game.Players.PlayerAdded:Connect(function(player)
	
	local totalKills
	local success, err=pcall(function()
		totalKills = killSave:GetAsync("Player_"..player.UserId)
	end)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local kills = Instance.new("IntValue")
	
	if success then
		kills.Value = totalKills
	else
		kills.Value = 0
	end
	
	kills.Name = "Kills" -- Name that shows in game.
	kills.Value = 0 -- Value of Kills When A Player Joins.
	kills.Parent = leaderstats
	
	local rank = Instance.new("StringValue")
	rank.Name = "Rank" -- Same as Line 7.
	rank.Value = "Newbie"
	rank.Parent = leaderstats
	
	local function updateKills(newKills)
		if newKills then
			
		if newKills >= 20 then -- Change number for the amount of kills to rank up.
			rank.Value = "Intermediate" -- New rank name.
		end
		if newKills >= 30 then -- Change number for the amount of kills to rank up.
			rank.Value = "Initiated" -- New rank name.
		end
		if newKills >= 40 then -- Change number for the amount of kills to rank up.
			rank.Value = "Capable" -- New rank name.
		end
		if newKills >= 50 then -- Change number for the amount of kills to rank up.
			rank.Value = "Skilled" -- New rank name.
		end
		if newKills >= 100 then -- Change number for the amount of kills to rank up.
			rank.Value = "Proficient" -- New rank name.
		end
		if newKills >= 200 then -- Change number for the amount of kills to rank up.
			rank.Value = "Professional" -- New rank name.
		end
		if newKills >= 300 then -- Change number for the amount of kills to rank up.
			rank.Value = "Specialist" -- New rank name.
		end
		if newKills >= 400 then -- Change number for the amount of kills to rank up.
			rank.Value = "Advanced" -- New rank name.
		end
		if newKills >= 500 then -- Change number for the amount of kills to rank up.
			rank.Value = "Expert" -- New rank name.
		end
		if newKills >= 1000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Incredible" -- New rank name.
		end
		if newKills >= 2000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Outstanding" -- New rank name.
		end
		if newKills >= 3000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Elite" -- New rank name.
		end
		if newKills >= 4000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Superior" -- New rank name.
		end
		if newKills >= 5000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Master" -- New rank name.
		end
		if newKills >= 10000 then -- Change number for the amount of kills to rank up.
			rank.Value = "Ultimate Master" -- New rank name.
			end
		end
	end
	
	
	updateKills()
	kills.Changed:Connect(updateKills)
	
end)

local function save(player)
	local success, err = pcall(function()
		killSave:SetAsync("Player"..player.UserId,player.leaderstats.Kills.Value)
	end)
	
	if success then
		print("Saving Succeeded.")
	else
		print("Failure.")
	end
end

local function autosave()
	while wait(15)do
for i, player in pairs(game:GetService("Players"):GetPlayers()) do
			print("Saving")
			save(player)
		end
	end
end

can u send the place or a file for it, ill fix and resend

Scripts are in ServerScriptService
The tool is in Staterpack and more are in ServerStorage.

CopyOfGame2.rbxl (312.8 KB)

1 Like

it works with zombies but not players somehow
detects zombies but not players, sry idk what to do and i gtg