How do I prevent tools from disappearing from the player's backpack after death?
I created a shop that sold guns, and it all worked fine. The thing is, when the player dies, they lose all the guns that they bought, and only the starter gun remains in their inventory.
Here's my LocalScript
inside of one of the guns:
001 | game.Players.LocalPlayer.Backpack.ChildAdded:Connect( function () |
004 | local character = game.Players.LocalPlayer.Character |
005 | local function createBullet() |
006 | local bulletPart = workspace.bullet:Clone() |
007 | bulletPart.Parent = workspace |
008 | bulletPart.Position = script.Parent.Handle.Part.Position |
009 | bulletPart.Orientation = bulletPart.Orientation + (script.Parent.Handle.Orientation - Vector 3. new( 0 , 90 , 0 )) |
011 | bulletPart.CFrame = bulletPart.CFrame * CFrame.new( 0 , 0 ,i) |
017 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
018 | while not character do |
019 | character.AncestryChanged:Wait() |
022 | local hum = character:WaitForChild( 'Humanoid' ) |
023 | local reloadAnim = hum:LoadAnimation(script.Parent.Animation) |
024 | local fireAnim = hum:LoadAnimation(script.Parent.fire) |
026 | script.Parent:WaitForChild( 'MaxAmmo' ).Value = MaxAmmo |
027 | script.Parent:WaitForChild( 'Ammo' ).Value = Ammo |
029 | local canDamage = true |
030 | local Reloading = false |
031 | local uis = game:GetService( "UserInputService" ) |
033 | script.Parent.Equipped:Connect( function () |
034 | uis.MouseIconEnabled = true |
037 | script.Parent.Unequipped:Connect( function () |
038 | uis.MouseIconEnabled = false |
043 | local isDamaging = false |
045 | script.Parent.Activated:Connect( function () |
047 | if Ammo > 0 and not Reloading then |
048 | while canFire = = true do |
050 | script.Parent.Handle.fire:Play() |
053 | script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = Ammo.. " / " ..MaxAmmo |
054 | script.Parent.Handle.Part.FrontFlash.Transparency = 0 |
055 | script.Parent.Handle.Part.BackFlash.Transparency = 0 |
057 | script.Parent.Handle.Part.FrontFlash.Transparency = 1 |
058 | script.Parent.Handle.Part.BackFlash.Transparency = 1 |
065 | if isDamaging = = true then |
066 | game.Players.LocalPlayer:GetMouse().Target.Parent:WaitForChild( 'EnemyHum' ):TakeDamage( 6 ) |
070 | elseif Reloading = = false then |
071 | uis.InputBegan:Connect( function (keyCode) |
072 | if keyCode.keyCode = = Enum.KeyCode.R then |
073 | if Reloading = = false then |
077 | script.Parent.Handle.reload:Play() |
078 | wait(script.Parent.Handle.reload.TimeLength) |
079 | script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = "40 / 40" |
088 | script.Parent.Unequipped:Connect( function () |
093 | script.Parent.Handle.reload:Stop() |
096 | script.Parent.Deactivated:Connect( function () |
Yes, this is long and I'm very sorry for that. I really need answers though, because I want this game out as soon as possible.
**