You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear! I would like to have a functioning tool shop.
-
What is the issue? Include screenshots / videos if possible! When I buy one tool, it works alright, but when I buy another one, it goes into the players backpack, but destroys the first tool. When I equip an tool, I’m able to buy another one without replacing it, but as soon as I unequip it, it is destroyed. I have never come across this issue in my years of scripting.
As you can see in this video, buying a tool replaces the already existing one.
local Player = script.Parent.Parent.Parent
local leaderboard = nil
local Gems = nil
task.wait(3)
if Player:FindFirstChild("leaderboard") then
if Player.leaderboard:FindFirstChild("Gems") then
Gems = Player.leaderboard.Gems
end
end
if Player:FindFirstChild("leaderstats") then
if Player.leaderstats:FindFirstChild("Gems") then
Gems = Player.leaderstats.Gems
end
end
for _, tool in pairs(game.ReplicatedStorage:WaitForChild("Tools"):GetChildren()) do
if tool:IsA("Tool") then
local ToolFrame = script.ToolFrame:Clone()
if tool:FindFirstChild("Price") then
Price = tool:FindFirstChild("Price").Value
ToolFrame.Price.Text = tool:FindFirstChild("Price").Value.." GEMS"
end
local Price = 100
ToolFrame.Price.Text = "100 GEMS"
ToolFrame["Item Name"].Text = tool.Name
ToolFrame["Item Name"].Name = tool.Name
ToolFrame.Display.ImageLabel.Image = tool.TextureId
ToolFrame.Parent = script.Parent.Frame["Rectangle 30"]
-- this is the part that puts the tool in the player's backpack upon purchase
ToolFrame.Buy.PURCHASE.MouseButton1Click:Connect(function()
if Player.Backpack:FindFirstChild(tool.Name) then
warn("already purchased!")
else
if Gems == nil or Gems.Value < Price then
script.Parent.LocalScript.RemoteEvent:FireAllClients(false)
ToolFrame.BuyButton.BackgroundColor3 = Color3.fromRGB(255, 28, 43)
task.wait(1)
ToolFrame.BuyButton.BackgroundColor3 = Color3.fromRGB(41, 255, 66)
return
end
Gems.Value -= Price
tool:Clone()
tool.Parent = Player.Backpack
script.Parent.clocal.RemoteEvent:FireAllClients(true)
end
end)
end
end
- What solutions have you tried so far? I have searched far and wide across the internet, but cannot find an issue quite like mine. It must be something very simple that I have overlooked, but I can’t figure it out. Any help is appreciated. Thank you!