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

Help need my script for a wokring kills and deaths leaderstats does not work?

The code I made, the deaths works but not kills. Can somebody help?

game.Players.PlayerAdded:Connect(function(plr) local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = plr

local kills = Instance.new("IntValue")
kills.Name = "KOs" 
kills.Parent = stats

local deaths = Instance.new("IntValue")
deaths.Name = "WOs" 
deaths.Parent = stats

plr.CharacterAdded:Connect(function(char)
    local humanoid
    repeat
        humanoid = char:FindFirstChild("Humanoid")
        wait()
        
    until humanoid
    humanoid.Died:Connect(function(char)
        deaths.Value = deaths.Value + 1
        
        local tag = humanoid:FindFirstChild("creator")
        if tag
        then
            local killer = tag.Value
            if killer then
                
            
                killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
                end
        end
    end)
end)

end)

1 comment

0

Is this supposed to be a regular leaderstats script or is it a custom leaderstats?

1 answer

✓ Accepted answer
local currencyName = "DR and DP" 
local DataStore = game:GetService("DataStoreService"):GetDataStore("UC")

game.Players.PlayerAdded:Connect(function(player)
	
	local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = player

        local DP = Instance.new("IntValue")
        DP.Name = "Points"
        DP.Parent = stats

        local DR = Instance.new("IntValue")
        DR.Name = "Rolls"
        DR.Parent = stats
	
	local ID = currencyName.."-"..player.UserId
	local savedata = nil
	
	pcall(function()
		savedData = DataStore:GetAsync(ID)
	end)
	
	if savedData ~= nil then
		DP.Value = savedData
		DR.Value = savedData
		print("Data loaded")
	else
		DP.Value = 0 
		DR.Value = 0
		print("New player to the game")
	end
	

end)

game.Players.PlayerRemoving:Connect(function(player)
	local ID = currencyName.." - "..player.UserId
	DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)

game:BindToClose(function()
	
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			player:Kick("This Game is Shutting down for saving data and adding updates plz rejoin :D ")
		end
	end

	wait(5)
	
end)

This code does not save, but it should, anyways, it does make a leaderstats appear with two variables, just change it to your stuff and it should work.

1 comment

0

ayyyyy

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