What do you want to achieve?
Amount of energy to increase when input is down
What is the issue?
The While loop that increases the amount of energy doesn’t stop after it reaches the value of the player’s maximum energy
What solutions have you tried so far?
This is the server script:
local CurrentAnimations = {}
local cancharge = true
local function startcharge(player,maxki,ki)
local Character = player.Character
local fx1 = game.ReplicatedStorage.Particles.Charge:Clone()
local fx2 = game.ReplicatedStorage.Particles.Spread:Clone()
fx1.Parent = Character.HumanoidRootPart
fx2.Parent = Character.HumanoidRootPart
cancharge = true
local animc = script.charge:Clone()
Character.HumanoidRootPart.Anchored = true
animc.Parent = Character.Humanoid
CurrentAnimations[player.Name] = Character.Humanoid:LoadAnimation(animc)
CurrentAnimations[player.Name]:Play()
while cancharge == true do
ki.Value = ki.Value + 1
if ki.Value == maxki.Value then
cancharge = false
print("cap reached")
end
wait(0.09)
end
end
local function endcharge(player)
local Character = player.Character
cancharge = false
Character.HumanoidRootPart.Charge:Destroy()
Character.HumanoidRootPart.Spread:Destroy()
Character.HumanoidRootPart.Anchored = false
CurrentAnimations[player.Name]:Stop()
CurrentAnimations[player.Name] = nil
end
game.ReplicatedStorage.Events.EnergyCharge.OnServerEvent:Connect(function(player,maxki,ki)
startcharge(player,maxki,ki)
end)
game.ReplicatedStorage.Events.StopEnergyCharge.OnServerEvent:Connect(function(player,ki)
endcharge(player)
end)
this script is used with InputBegan and InputEnded
local CurrentAnimations = {}
local cancharge = true
local function startcharge(player,maxki,ki)
local Character = player.Character
local fx1 = game.ReplicatedStorage.Particles.Charge:Clone()
local fx2 = game.ReplicatedStorage.Particles.Spread:Clone()
fx1.Parent = Character.HumanoidRootPart
fx2.Parent = Character.HumanoidRootPart
cancharge = true
local animc = script.charge:Clone()
Character.HumanoidRootPart.Anchored = true
animc.Parent = Character.Humanoid
CurrentAnimations[player.Name] = Character.Humanoid:LoadAnimation(animc)
CurrentAnimations[player.Name]:Play()
while cancharge == true do
ki.Value = ki.Value + 1
if ki.Value == maxki.Value then
cancharge = false
print("cap reached")
break
end
wait(0.09)
end
end
local function endcharge(player)
local Character = player.Character
cancharge = false
Character.HumanoidRootPart.Charge:Destroy()
Character.HumanoidRootPart.Spread:Destroy()
Character.HumanoidRootPart.Anchored = false
CurrentAnimations[player.Name]:Stop()
CurrentAnimations[player.Name] = nil
end
game.ReplicatedStorage.Events.EnergyCharge.OnServerEvent:Connect(function(player,maxki,ki)
startcharge(player,maxki,ki)
end)
game.ReplicatedStorage.Events.StopEnergyCharge.OnServerEvent:Connect(function(player,ki)
endcharge(player)
end)
What’s the value of maxki.Value, is it an integer?
What does these print?
while cancharge do
ki.Value += 1
print(ki.Value, maxki.Value)
if ki.Value == maxki.Value then
cancharge = false
print("cap reached")
end
wait(0.09)
end
As you said it isn’t printing anything, it shows that ki.Value == maxki.Value never evalulated to true?
Alternatively you can try ki.Value >= maxki.Value instead.