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

I'm confused on how to add something to a players starter pack using script?

This is my code.....

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
	                         -- *Right here I'd like to add an item to the starter pack* 
	                     end
                        end
                    end
               end
         	if tag.Value ~= nil then
        	end
           end
  	end)
    end)
end)

Does anyone know how to do this? If you do, PLEASE TELL ME!


Edit: format your code correctly! ~ incapaxx

2 comments

0

leaderstats are suppose to be in ServerScriptService?

0

?

1 answer

✓ Accepted answer

There is an example script on how to add a tool to a player's backpack.

game.Players.PlayerAdded:Connect(function(plr)
	plr:WaitForChild("Backpack")
	local cl = game.ReplicatedStorage.Tool:Clone()
	cl.Name = "Tool"
	cl.Parent = plr.Backpack -- this is the point of the script
end)

The point of that is just moving the tool to the player's backpack, I have commented there. Hope this helps.

8 comments

0

What kind of variable name is plr and is there a reason you can't use :WaitForChild("Backpack")

0

What's wrong with plr? Short of player... And no, I just forget about that.

0

player is clearer than plr. client is also a good variable name; it's general.

0

I (and many-many others) always use plr, it's shorter. I don't know why don't you like that.

0

Again, I gave a good reasoning. But seriously instead of that long wait just use :WaitForChild()

0

Also, everyone knows that the first argument of that event is the player, who joined. I can call that anything

0

Okay I edited the script

0

But incapaxx this didn't worked for me, did I do anything wrong?

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