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

I have a problem with my leaderboard? [Unanswered]

In this script, it creates the leaderboard, but doesn't award kills or gold. Help? No errors either.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
 
    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats

	local kills = Instance.new("IntValue")
  	kills.Name = "Kills"
	kills.Value = 0
    kills.Parent = leaderstats

	local level = Instance.new("IntValue")
  	level.Name = "Level"
    level.Value = 1
    level.Parent = leaderstats

	game.Players.PlayerAdded:connect(function(player)
		player.CharacterAdded:connect(function(character)
			character.Humanoid.Died:connect(function()
				local killer = character.Humanoid:findFirstChild("creator")
				if killer then
					killer.leaderstats.Kills.Value = killer.Value.Kills.Value + 1
					killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + 3
				end
			end)
		end)
	end)
end)

1 comment

0

I don't have time to read through that thoroughly, but NEVER EVER EVER use two identical events in the same script! It's scary, and 100% pointless! Just use a SINGLE PlayerAdded event for everything you want done.

1 answer

I think the problem has to be in the third function. Try this:

 game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            character.Humanoid.Died:connect(function(chr) -- I gave this function a parameter
                local killer = chr.Humanoid:findFirstChild("creator") -- switched character to chr
                if killer then
                    killer.leaderstats.Kills.Value = killer.Value.Kills.Value + 1
                    killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + 3

Hope this helps.

1 comment

0

didn't work.

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