Why do the weapons not remain in the player's backpack? [Solved]
This question has been solved by the original poster.
Hello,
Looking at a previous problem from a different angle. Basically, after a player purchases a weapon, it appears in the StarterGear and Backpack, but once the player dies and re-spawns, the weapon is still in the StarterGear, but is no longer accessible via the Backpack.
Below is my Purchase script within my ShopGui which purchases the item and adds it to the StarterGear and BackPack:
01 | local plr = game.Players.LocalPlayer |
02 | local replicatedstorage = game:GetService( 'ReplicatedStorage' ) |
04 | local points = plr.leaderstats.Points |
05 | script.Parent.MouseButton 1 Click:connect( function () |
06 | if plr.Backpack:FindFirstChild( 'GravityCoil' ) or plr.StarterGear:FindFirstChild( 'GravityCoil' ) or game.Workspace [ plr.Name ] :FindFirstChild( 'GravityCoil' ) then |
07 | script.Parent.Parent.TextLabel.Text = 'You have already bought this item!' |
09 | script.Parent.Parent.TextLabel.Text = 'Welcome to the shop' |
12 | if plr.leaderstats.Points.Value > = amount then |
13 | replicatedstorage.GravityCoil:Clone().Parent = plr.Backpack |
14 | replicatedstorage.GravityCoil:Clone().Parent = plr.StarterGear |
15 | plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - amount |
18 | local pointsrequired = amount - points.Value |
19 | script.Parent.Parent.TextLabel.Text = 'You need ' ..pointsrequired.. ' more Points to buy this item!' |
21 | script.Parent.Parent.TextLabel.Text = 'Welcome to the shop' |
Now, inside my main script right after the random map process happens, I have the following code that adds a Sword to the player. I'm wondering if this code is interfering with the code above and preventing items from returning to a player's backpack after the re-spawn?
My main script is essentially the following:
06 | local sword = game.ReplicatedStorage.Sword |
07 | local newsword = sword:Clone() |
08 | newsword.Parent = player.Backpack |
I've been given the following script to place inside Workspace, but it doesn't solve the problem of the weapons disappearing from the backpack on re-spawn:
01 | local wm = Instance.new( "Model" ) |
04 | function give(weap, player) |
06 | for _, w in ipairs (player.Weaps:GetChildren()) do |
07 | if w.Name = = weap.Name then return end |
10 | for _, w in ipairs (game.StarterPack:GetChildren()) do |
11 | if w.Name = = weap.Name then return end |
14 | weap:clone().Parent = player.Weaps |
17 | game.Players.ChildAdded:connect( function (p) |
20 | p.Character.ChildAdded:connect( function (wep) |
21 | if wep.className = = "Tool" then |
25 | p.Changed:connect( function (pr) |
26 | if pr = = "Character" then |
27 | for _, w in ipairs (p.Weaps:GetChildren()) do |
28 | w:clone().Parent = p.Backpack |
30 | p.Character.ChildAdded:connect( function (wep) |
31 | if wep.className = = "Tool" then |
37 | p.Backpack.ChildAdded:connect( function (h) |
38 | if h.className = = "HopperBin" then |
I know I've got to be overlooking or mistyping something very simple, I'm all ears/eyes for any solution here. x_x Thank you!