Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why do the weapons not remain in the player's backpack? [Solved]

Asked by 8 years ago
Edited by OldPalHappy 8 years ago

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:

01local plr = game.Players.LocalPlayer
02local replicatedstorage = game:GetService('ReplicatedStorage')
03local amount = 30
04local points = plr.leaderstats.Points
05script.Parent.MouseButton1Click:connect(function()
06    if plr.Backpack:FindFirstChild('GravityCoil') or plr.StarterGear:FindFirstChild('GravityCoil') or game.Workspace[plr.Name]:FindFirstChild('GravityCoil')then -- Change the name of the items.      
07         script.Parent.Parent.TextLabel.Text = 'You have already bought this item!'
08            wait(3)
09         script.Parent.Parent.TextLabel.Text = 'Welcome to the shop'
10         else
11 
12    if plr.leaderstats.Points.Value >= amount then
13            replicatedstorage.GravityCoil:Clone().Parent = plr.Backpack -- Item added to Backpack.
14            replicatedstorage.GravityCoil:Clone().Parent = plr.StarterGear -- Item added to StarterGear.
15            plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - amount         
View all 24 lines...

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:

01-- Variables defined
02-- Sets up Round
03-- Teleport players to the map
04-- Adds basic sword to player
05 
06local sword = game.ReplicatedStorage.Sword
07            local newsword = sword:Clone()
08            newsword.Parent = player.Backpack
09 
10        end
11    end
12end
13 
14-- End of Round/Teleport survivors back to the lobby
15-- Rinse/Repeat

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:

01local wm = Instance.new("Model")
02wm.Name = "Weaps"
03 
04function give(weap, player) --add a weap to a player's weaps
05    --return if they allready have a copy
06    for _, w in ipairs(player.Weaps:GetChildren()) do
07        if w.Name == weap.Name then return end
08    end
09    --return if the weaps is a startpack one
10    for _, w in ipairs(game.StarterPack:GetChildren()) do
11        if w.Name == weap.Name then return end
12    end
13    --add it to thier weaps
14    weap:clone().Parent = player.Weaps
15end
View all 42 lines...

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!

0
isn't the use of HopperBins deprecated? Maybe this could be causing your disappearing items Nogalo 148 — 8y
0
Maybe, but even without that script with the HopperBins, my items were still disappearing. Never2Humble 90 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This was solved in the strangest way. I opened up a new session of studio, copied all of the contents from the old one into the new one...and it worked. I changed nothing. I don't understand what happened, but as long as it works. Roblox works in mysterious ways I guess.

0
gg OldPalHappy 1477 — 8y
Ad

Answer this question