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

Why doesn't the weapon stay in the backpack when I die?

So I have this script inside of StarterGui and i want it to make the weapon go in your backpack when you click the equip button. When you click it you do get the weapon, but when you die you lose it. Why is this and could anyone help me how to make it so that the weapon stays in your backpack even when you die?

--Note: in the script only the lines where it clones the weapon are really important I think.

script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Parent.Parent.Parent.Parent.Parent.Backpack.Primary.Value then
		script.Parent.Parent.Parent.Parent.Parent.Parent.Backpack.Primary.Value = false
		local CloneGalil = game.ServerStorage["Galil AR"]:clone()
		CloneGalil.Parent = script.Parent.Parent.Parent.Parent.Parent.Parent.Backpack
		script.Parent.Parent.Parent.Dummy.Primary.Weapon.Weapon.Visible = true
		script.Parent.Text = "Weapon Equipped"
		wait(1)
		script.Parent.Text = "Equip"
		script.Parent.Visible = false
	else
		script.Parent.BackgroundColor3 = Color3.new(1,0,0)
		script.Parent.Parent.Parent.Parent.PrimaryAlreadyEquipped.Visible = true
		wait(1)
		script.Parent.BackgroundColor3 = Color3.new(0,1,0)
		script.Parent.Parent.Parent.Parent.PrimaryAlreadyEquipped.Visible = false
		script.Parent.Text = "Equip"
		script.Parent.Visible = false
	end
	
end)

1 comment

0

Put the wepon in starterpack if you want it to stay

1 answer

✓ Accepted answer

I would like to re-script your entire code, but that wouldn't be a good answer. Why? Because you wouldn't learn a single thing from copying and pasting.

So, I am going to give you a tip. It will be your job to apply it to your Script. Every Player has 4 children: "Backpack", "StarterGear", "PlayerGui" and "PlayerScripts".

Notice the StarterGear?

Here is what the Wiki says about it: StarterGear is a container that is automatically inserted into each Player when the player joins the game. If a game allows gear, all of a player's appropriate gear will be inserted in to StarterGear when the player joins the game. Whenever the player's Character spawns, all of the contents of that player's StarterGear will get copied into the player's Backpack.

All you need to do is copy the Tools to someone's StarterGear.

However, there is one problem!

If you copy Tools to a Player's StarterGear for the first time, you won't see it inside the Player's Backpack. To fix this, simply create another line of Code which will copy the Tool to the Player's Backpack.

So, in short:

Copy the Tool he/she has chosen to the Player's StarterGear and Backpack.

Let me know if you have any questions.

3 comments

0

Ok, thanks a lot for the answer, I thought the startergear was only for things you obtain through roblox not through the game. I'll immediately try it out and let you know if it works. Btw, you said you wanted to re-script my entire code, are there any other mistakes I made then or things that could be better? I' really just a beginner scripter. :)

0

Just tested it, it works. Thanks a lot again! :)

0

You are welcome! I wish you luck with whatever you are making.

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