I have a pawn shop in my game, but the problem is is that the purchase script is not working for when I want to purchase someone else's lightsaber or blaster. here is the code provided:
-- Purchase Script
local plr = game.Players.LocalPlayer
local bp = plr.Backpack
local sg = plr.StarterGear
local gp = plr.leaderstats:FindFirstChild("Credits")
while wait() do
for _, v in pairs(game.ReplicatedStorage.PawnStorage:GetChildren()) do
if v:IsA("Tool") then
local OfferFrame = game.ReplicatedStorage.PawnGuis.PawnFrame:Clone()
OfferFrame.ItemName.Text = v.SaleStats.ItemName.Value
OfferFrame.ItemDescription.Text = v.SaleStats.ItemDescription.Value
OfferFrame.PriceDisplay.Text = tostring(v.SaleStats.PriceDisplay.Value)
OfferFrame.Purchase.MouseButton1Click:connect(function()
local sellvalue = tonumber(OfferFrame.PriceDisplay.Text)
local gp2 = v.SaleStats.Seller.Value
v.Parent = plr.Backpack
v:Clone().Parent = plr.StarterGear
game.Players[gp2].leaderstats.Credits.Value = game.Players[gp2].leaderstats.Credits.Value + v.SaleStats.PriceDisplay.Value
gp.Value = gp.Value - v.SaleStats.PriceDisplay.Value
print"Pawned Transaction Successful" game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You bought " ..v.Name.. " for " ..tostring(v.SaleStats.PriceDisplay.Value).. " Credits from" .. gp2.Value .. "!",2)
end)
OfferFrame.Parent = script.Parent
end
end
end
-- vend script
local ShopS = require(script.Parent.ShopStock)
local SS2 = require(script.Parent.ShopStock2)
local Stock = script.Parent.Frame.Stock
local Stock2 = script.Parent.Frame.Stock2
local plr = game.Players.LocalPlayer
local gp = plr.leaderstats:FindFirstChild("Credits")
while wait() do
if Stock.Visible == true then
for i,v in pairs(Stock:GetChildren()) do
v.ItemName.Text = ShopS.Items[i]
v.ItemDescription.Text = ShopS.Desc[i]
v.PriceDisplay.Text = ShopS.Prices[i]
v.PriceDisplay.MouseButton1Click:connect(function()
local bp = plr.Backpack
local sg = plr.StarterGear
local bptool = bp:FindFirstChild(ShopS.Items[i])
local sgtool = sg:FindFirstChild(ShopS.Items[i])
local sellvalue = ShopS.Prices[i]
if bptool ~= nil and sgtool ~= nil then
sgtool:Destroy()
bptool.Parent = game.ReplicatedStorage.PawnStorage
local SaleStats = Instance.new("IntValue",bptool)
SaleStats.Name = "SaleStats"
local iName = Instance.new("StringValue",SaleStats)
iName.Name = "ItemName"
iName.Value = v.ItemName.Text
local iDesc = Instance.new("StringValue",SaleStats)
iDesc.Name = "ItemDescription"
iDesc.Value = v.ItemDescription.Text
local iPrice = Instance.new("IntValue",SaleStats)
iPrice.Name = "PriceDisplay"
iPrice.Value = tonumber(v.PriceDisplay.Text)
local Seller = Instance.new("StringValue",SaleStats)
Seller.Name = "Seller"
Seller.Value = plr.Name
local Seller2 = Seller:Clone()
Seller2.Parent = bptool
local GP = Instance.new("ObjectValue",SaleStats)
GP.Name = "GoldAccount"
GP.Value = gp
game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You sold " ..v.ItemName.Text.. " for " ..v.PriceDisplay.Text.. " Gold!",2)
elseif bptool == nil and sgtool ~= nil then
game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You sold " ..v.ItemName.Text.. " for " ..v.PriceDisplay.Text.. " Gold!",2)
else game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You don't have the" ..v.ItemName.Text.. "!",2)
end
end)
end
elseif script.Parent.Frame.Buy.Visible == true then
elseif Stock2.Visible == true then
for i,v in pairs(Stock2:GetChildren()) do
v.ItemName.Text = SS2.Items[i]
v.ItemDescription.Text = SS2.Desc[i]
v.PriceDisplay.Text = SS2.Prices[i]
v.PriceDisplay.MouseButton1Click:connect(function()
local bp = plr.Backpack
local sg = plr.StarterGear
local bptool = bp:FindFirstChild(SS2.Items[i])
local sgtool = sg:FindFirstChild(SS2.Items[i])
local sellvalue = SS2.Prices[i]
if bptool ~= nil and sgtool ~= nil or (bptool ~= nil and sgtool == nil) then
game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You sold " ..v.ItemName.Text.. " for " ..v.PriceDisplay.Text.. " Gold!",2)
local SaleStats = Instance.new("IntValue",bptool)
SaleStats.Name = "SaleStats"
local iName = Instance.new("StringValue",SaleStats)
iName.Name = "ItemName"
iName.Value = v.ItemName.Text
local iDesc = Instance.new("StringValue",SaleStats)
iDesc.Name = "ItemDescription"
iDesc.Value = v.ItemDescription.Text
local iPrice = Instance.new("IntValue",SaleStats)
iPrice.Name = "PriceDisplay"
iPrice.Value = tonumber(v.PriceDisplay.Text)
local Seller = Instance.new("StringValue",SaleStats)
Seller.Name = "Seller"
Seller.Value = plr.Name
local Seller2 = Seller:Clone()
Seller2.Parent = bptool
local GP = Instance.new("ObjectValue",SaleStats)
GP.Name = "GoldAccount"
GP.Value = gp
bptool.Parent = game.ReplicatedStorage.PawnStorage
local GP = Instance.new("ObjectValue",sgtool)
GP.Name = "GoldAccount"
GP.Value = gp
elseif bptool == nil and sgtool ~= nil then
game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You sold " ..v.ItemName.Text.. " for " ..v.PriceDisplay.Text.. " Gold!",2)
else game.ReplicatedStorage.RemoteService.ShowDialog:FireClient(plr,plr.Name,"You don't have the" ..v.ItemName.Text.. "!",2)
end
end)
end
end
end
I have no other ideas.
