Hello!
I have a purchase script below that allows a player to successfully add an item to their inventory after purchase from the in-game shop and then prevents them from re-purchasing a duplicate item. But I have two problems.
First - after the player re-spawns, the item disappears and is no longer in their inventory. If the player then tries to repurchase the item they're unable to, as they receive the notice that they've already purchased it - which is intended to prevent accidental duplicate purchases. But, how do I make the item survive the respawn and remain usable to the player?
Here is the purchase script below:
local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService('ReplicatedStorage')
local amount = 100
local points = plr.leaderstats.Points
script.Parent.MouseButton1Click:connect(function()
if plr.Backpack:FindFirstChild('RocketLauncher') or plr.StarterGear:FindFirstChild('RocketLauncher') or game.Workspace[plr.Name]:FindFirstChild('RocketLauncher')then
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.RocketLauncher:Clone().Parent = plr.Backpack
replicatedstorage.RocketLauncher:Clone().Parent = plr.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)
Second - After the item is purchased, how do I disable the use of items while inside the Lobby? All of my scripting attempts result in failure, or stops the game. I tried adapting an old Healing Block script by inserting a block to take up the entire lobby with a disabling backpack script, but I've made a real mess of the code:
local isOn = true
function onTouch(hit)
if (isOn == false) then return end
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local dis = script:FindFirstChild("Disable"):Clone()
if dis then
local plrGui = plr:WaitForChild("PlayerGui")
dis.Parent = plrGui
dis.Disabled = false
end
end)
turnOff()
end
end
connection = script.Parent.BackPackDisabler.Touched:connect(onTouch)
while true do
wait(cooldown)
if (isOn == false) then turnOn() end
end
Thank you very much for any assistance! :)

2 comments
put it in StarterGear
I did, but when the character re-spawns, the item is no longer accessible.