I’m encountering an issue where the values of workerLevel and machineLevel do not update properly in the script. Despite the values changing in the interface, the script always reads them as 1. This affects the calculation of income and money generation based on these levels. I’ve added debugging code to print their values, but they remain stuck at 1. How can I fix this issue and ensure the values are properly updated and recognized in the script? I’m using a server script
local prompt = script.Parent:FindFirstChildOfClass("ProximityPrompt")
local billboardgui = script.Parent.BillboardGui
local TextGive = billboardgui.TextCanGive
if prompt then
prompt.Triggered:Connect(function(player)
if not prompt.Enabled then return end
prompt.Enabled = false
local cash = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("cash")
if not cash or cash.Value < 200 then
warn("Not enough money to spawn a worker")
return
end
cash.Value = cash.Value - 200
local worker = game.ServerStorage.Worker:Clone()
worker.Parent = workspace
worker:SetPrimaryPartCFrame(prompt.Parent.PrimaryPart.CFrame * CFrame.new(0, 4.5, 0) * CFrame.Angles(0, math.rad(-90), 0))
local leaderstats = player:FindFirstChild("leaderstatsvalue")
if leaderstats then
local cashCanGive = leaderstats:FindFirstChild("CashCanGive")
local derevo = leaderstats:FindFirstChild("wood")
local steel = leaderstats:FindFirstChild("steel")
local workerLevel = leaderstats:FindFirstChild("workerLevel")
local machineLevel = leaderstats:FindFirstChild("machineLevel")
if not (cashCanGive and derevo and steel and workerLevel and machineLevel) then
warn("Not enough data to calculate income")
return
end
local function calculateIncome()
local income = 10 * (1 + (workerLevel.Value - 1) * 0.2 + (machineLevel.Value - 1) * 0.3)
TextGive.Text = "+$" .. math.floor(income)
return income
end
while derevo.Value >= 2 and steel.Value >= 0.2 do
print("workerLevel: " .. workerLevel.Value) -- Откладка: вывод значения workerLevel
print("machineLevel: " .. machineLevel.Value) -- Откладка: вывод значения machineLevel
local income = calculateIncome()
cashCanGive.Value = cashCanGive.Value + income
derevo.Value = derevo.Value - 2
steel.Value = steel.Value - 1
wait(5)
end
end
end)
end