here My Client Code:
for _, frame in ipairs(A:GetChildren()) do
if frame:IsA("Frame") then
local buyLvlPrice = frame:FindFirstChild("BuyLvlPrice")
local giveMoneyInHour = frame:FindFirstChild("GiveMoneyInHour")
local levelSell = frame:FindFirstChild("LevelSell")
local money = frame:FindFirstChild("Money")
local buyLvl = frame:FindFirstChild("BuyLvl")
if buyLvlPrice and giveMoneyInHour and levelSell and money and buyLvl then
-- Инициализация количества купленных уровней
local boughtLevels = 0
local initialGiveMoneyInHour = giveMoneyInHour.Value -- Сохраняем исходное значение
buyLvl.Text = "Купить (x" .. boughtLevels .. ")"
-- Обновление информации на кнопке "Купить"
local function updateBuyButton()
buyLvl.Text = "lvl " .. boughtLevels
levelSell.Text = buyLvlPrice.Value
money.Text = boughtLevels * initialGiveMoneyInHour
end
-- Обработка клика по кнопке "Купить"
buyLvl.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
if player.Money.Value >= buyLvlPrice.Value then
game.ReplicatedStorage.MoneyGet:FireServer(-buyLvlPrice.Value)
game.ReplicatedStorage.FireBuy:FireServer(initialGiveMoneyInHour)
boughtLevels = boughtLevels + 1
buyLvlPrice.Value *= 1.2
giveMoneyInHour.Value *= 1
updateBuyButton()
else
task.spawn(function()
player.PlayerGui["No Money"].Enabled = true
wait(0.5)
player.PlayerGui["No Money"].Enabled = false
end)
end
local a = tostring(boughtLevels)
local b = levelSell.Text
local c = money.Text
task.wait()
game.ReplicatedStorage.Buyed:FireServer(a,b,c)
end)
updateBuyButton()
end
end
end
Here My Server Code:
game.ReplicatedStorage.Buyed.OnServerEvent:Connect(function(plr,boughtLevels,level,money)
-- I alr maked datastore but it didnt work, Hoe i can save data?
end)