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! :)
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)