Hello! I want to make a game where I need an axe shop. The problem is that I can purchase axes I already have and the textlable text isn’t “Owned”.
Server Script
local _L = {}
_L.__index = _L
local _A = require(game.ReplicatedStorage.Data.Axe)
game.ReplicatedStorage.Events.PurchaseAxe.OnServerEvent:Connect(function(player, axe)
_L.Purchase(player, axe)
end)
function _L.Purchase(player, axe)
if player.leaderstats.Coins.Value >= _A[axe].Cost and player.Axe[axe].Value == false then
player.Axe[axe].Value = true
player.leaderstats.Coins.Value -= _A[axe].Cost
else
print("Err: Not enough coins")
end
end
return _L
Local Script
local _L = {}
_L.__index = _L
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local viewportFrames = ReplicatedStorage:WaitForChild("ViewportFrames")
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local shopGui = playerGui:WaitForChild("AxeShop").BackgroundFrame
local itemFrame = shopGui.MainFrame.ItemFrame
local purchaseGui = itemFrame.BuyBackground.Buy
local _A = require(game.ReplicatedStorage.Data.Axe)
local function check(player, axe, button)
if player.Axe[axe].Value == true then
purchaseGui.Text = "Owned"
else
purchaseGui.Text = "C$".._A[button.Name].Cost
end
end
function _L.Init()
for i, button in pairs(shopGui.MainFrame.AxeHolder.Buttons:GetChildren()) do
button.MouseButton1Click:Connect(function()
for i, image in pairs(itemFrame:GetChildren()) do
if image:IsA("ViewportFrame") then
image.Parent = game.ReplicatedStorage.ViewportFrames
end
end
local axe = button.Name
game.ReplicatedStorage.Events.LoadAxe.OnClientEvent:Connect(function()
for i, v in pairs(shopGui.MainFrame.AxeHolder.Buttons:GetChildren()) do
check(player, axe, v)
end
end)
check(player, axe, button)
game.SoundService.Click:Play()
shopGui.MainFrame.ItemFrame.NameBackground.NameText.Text = button.Name
shopGui.MainFrame.ItemFrame.BuyBackground.Buy.Text = "C$".._A[button.Name].Cost
local clone = viewportFrames[button.Name]:Clone()
clone.Parent = itemFrame
clone.ZIndex = 20
clone.Position = UDim2.new(0.226, 0,0.209, 0)
if button.Name == "CrownAxe" then
shopGui.MainFrame.ItemFrame.BuyBackground.Buy.Text = "R$350"
end
end)
end
end
function _L.PurchaseAxe()
local axe = nil
purchaseGui.MouseButton1Click:Connect(function()
game.SoundService.Click:Play()
axe = shopGui.MainFrame.ItemFrame.NameBackground.NameText.Text
game.ReplicatedStorage.Events.PurchaseAxe:FireServer(axe)
for i, button in pairs(shopGui.MainFrame.AxeHolder.Buttons:GetChildren()) do
check(player, axe, button)
end
end)
end
_L.Init()
_L.PurchaseAxe()
return _L