The ClassicTrowel is under level, which is under, Player, which is under game. Please Help!


game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder",player)
    folder.Name = "leaderstats"
    local currency1 = Instance.new("IntValue",folder)
    currency1.Name = "Kills"

    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")

            if tag ~= nil then
	         if tag ~= nil then
                    local killer = tag.Value

                    if killer ~= nil then
                        -- Find the killer's leaderstats folder
                        local killerStats = killer:FindFirstChild("leaderstats")

                            if killerStats ~= nil then
                                -- Find the killer's Kills IntValue
                                local killerKills = killerStats:FindFirstChild("Kills")
                                -- Increase Kills as before
                                killerKills.Value = killerKills.Value + 1

                                if killerKills.Value == 1 then
		                     game.Players.PlayerAdded:Connect(function(plr)
			                  plr:WaitForChild("Backpack")
                                        local cl = game.Players.level.ClassicTrowel:Clone()
	                                 cl.Name = "Wall Builder"
	                                 cl.Parent = game.StarterPack --- I've tried changing this to plr.Backpack, plr.StarterPack, and game.Backpack
	                             end)
                                end
                            end
                        end
                    end
                if tag.Value ~= nil then
                end
            end
        end)
    end)
end)
	

What I want is a trowel to end up in your inventory after 1 kill. Right now, nothing's happening.

Also, the part that is wrong is

  if killerKills.Value == 1 then
		                     game.Players.PlayerAdded:Connect(function(plr)
			                  plr:WaitForChild("Backpack")
                                        local cl = game.Players.level.ClassicTrowel:Clone()
	                                 cl.Name = "Wall Builder"
	                                 cl.Parent = game.StarterPack --- I've tried changing this to plr.Backpack, plr.StarterPack, and game.Backpack
	                             end)
                                end

Everything else works

4 comments

1

These nested if statements give me a migraine. You gotta clean this rats nest of code up.

0

Fixed most indentation. You seriously need to get into the habit of indenting. Here's an article on how to write clean code: https://developer.roblox.com/articles/Writing-Clean-Code

0

why do u have 2 if tag ~= nil then?

0

Because it works