Hello good morning, developers is that apparently I have problems with the code of a ki recharge that I have but apparently does not load correctly, but loads a lot of ki but in the loop I put condition not to pass but still happens
SCRIPT:
local dataStore2 = require(game.ReplicatedStorage.BaseDatos.DataStore2)
local remote = game.ReplicatedStorage.Charging
local Charging = false
remote.OnServerEvent:Connect(function(player, value)
local BaseDatosEnergia = dataStore2("Energia", player)
local BaseDatosMaxEnergia = dataStore2("MaxEnergia", player)
local OperacionIncremento = ((1*(player.leaderstats.CarpetaEnergia.MaxEnergia.Value))/100)
-- Obteiendo valores
local Energia = (BaseDatosEnergia:Get() + 0.5) - (BaseDatosEnergia:Get() + 0.5) % 1
local MaxEnergia = (BaseDatosMaxEnergia:Get() + 0.5) - (BaseDatosMaxEnergia:Get() + 0.5) % 1
Charging = true
if value == "IsCharging" then
while Charging == true and Energia < MaxEnergia do
wait(.1)
BaseDatosEnergia:Increment(math.min((Energia + OperacionIncremento),MaxEnergia))
end
end
if value == "IsNotCharging" then
Charging = false
end
end)
LOCALSCRIPT:
local player = game.Players.LocalPlayer
local remote = game.ReplicatedStorage.Charging
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
remote:FireServer("IsCharging")
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
remote:FireServer("IsNotCharging")
end
end)
The values are stored in a datastore2, and when I press the C key, it increases more than it should. What can I do?