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

How to make things appear in backpack (inventory) after purchase?

Asked by 3 years ago

This is what I have so far. It takes out my money but doesn't give the item.

leaderboard script

game.Players.PlayerAdded:connect(function(plr)
    local stats = Instance.new("BoolValue",plr)
 stats.Name = "leaderstats"


  local cash = Instance.new("IntValue",stats)
 cash.Name = "Zims"
     cash.Value = 100

     local cash = Instance.new("IntValue",stats)
cash.Name = "Kills"
     cash.Value = 0
end)

local script to buy the item

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
    if player.leaderstats.Zims.Value >= 10 then
        player.leaderstats.Zims.Value = player.leaderstats.Zims.Value - 10

        game.ServerStorage.Tools.Sword:Clone().Parent = player:WaitForChild("Backpack")
    end
end)

2 answers

Log in to vote
0
Answered by 3 years ago
-- make 2nd script's 7. line :
local sword = game.ServerStorage.Tools.Sword:Clone().Parent = player.Backpack
Ad
Log in to vote
0
Answered by 3 years ago

My answer is similar to your attempt and the answer by @Omerevkizel

Replace line 7 on your purchase script:

local sword = game.ServerStorage.Tools.Sword:Clone()
sword.Parent = player.Backpack
sword:Clone().Parent = player.StarterGear

This script makes a clone of the sword and puts it in the player's backpack. Then it clones the clone and puts that in the player's StarterGear, which will keep the sword from getting destroyed when the player dies.

Answer this question