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 7 years ago
Edited by OldPalHappy 7 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:

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService('ReplicatedStorage')
local amount = 30
local points = plr.leaderstats.Points
script.Parent.MouseButton1Click:connect(function()
    if plr.Backpack:FindFirstChild('GravityCoil') or plr.StarterGear:FindFirstChild('GravityCoil') or game.Workspace[plr.Name]:FindFirstChild('GravityCoil')then -- Change the name of the items.       
         script.Parent.Parent.TextLabel.Text = 'You have already bought this item!'
            wait(3)
         script.Parent.Parent.TextLabel.Text = 'Welcome to the shop'
         else

    if plr.leaderstats.Points.Value >= amount then 
            replicatedstorage.GravityCoil:Clone().Parent = plr.Backpack -- Item added to Backpack.
            replicatedstorage.GravityCoil:Clone().Parent = plr.StarterGear -- Item added to StarterGear.
            plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - amount          
else 

local pointsrequired = amount - points.Value 
    script.Parent.Parent.TextLabel.Text = 'You need '..pointsrequired..' more Points to buy this item!'
        wait(3)
    script.Parent.Parent.TextLabel.Text = 'Welcome to the shop'
end
end
end)

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:

-- Variables defined
-- Sets up Round
-- Teleport players to the map
-- Adds basic sword to player

local sword = game.ReplicatedStorage.Sword
            local newsword = sword:Clone()
            newsword.Parent = player.Backpack

        end
    end
end

-- End of Round/Teleport survivors back to the lobby
-- 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:

local wm = Instance.new("Model")
wm.Name = "Weaps"

function give(weap, player) --add a weap to a player's weaps
    --return if they allready have a copy
    for _, w in ipairs(player.Weaps:GetChildren()) do
        if w.Name == weap.Name then return end
    end
    --return if the weaps is a startpack one
    for _, w in ipairs(game.StarterPack:GetChildren()) do
        if w.Name == weap.Name then return end
    end
    --add it to thier weaps
    weap:clone().Parent = player.Weaps
end

game.Players.ChildAdded:connect(function(p)
    wm:clone().Parent = p
    wait()
    p.Character.ChildAdded:connect(function(wep)
        if wep.className == "Tool" then
            give(wep, p)
        end
    end)
    p.Changed:connect(function(pr)
        if pr == "Character" then
            for _, w in ipairs(p.Weaps:GetChildren()) do
                w:clone().Parent = p.Backpack
            end
            p.Character.ChildAdded:connect(function(wep)
                if wep.className == "Tool" then
                    give(wep, p)
                end
            end)
        end
    end)
    p.Backpack.ChildAdded:connect(function(h)
        if h.className == "HopperBin" then
            give(h, p)      
        end
    end)
end)


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 — 7y
0
Maybe, but even without that script with the HopperBins, my items were still disappearing. Never2Humble 90 — 7y

1 answer

Log in to vote
0
Answered by 7 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 — 7y
Ad

Answer this question