I have a tool which will recharge over time and i want it to recharge after about 4 seconds, i want it to kinda tween so it looks cool recharging.
How should i go about doing this?
-The Script
RemoteEvent.OnServerEvent:Connect(function(plr, SetPosition, HitPosition)
local Sub = tool.Charge.Value - 20
local projectile = require(ServerScriptService.Modules.ProjectileMod).new(0.05, workspace:GetDescendants(), Vector3.new(0,0,0), 3, true, toolDummy, Explosion)
local Tween = TweenService:Create(tool.Charge, TweenInfo.new(0.8), {Value = Sub})
Tween:Play()
projectile:Cast(SetPosition, HitPosition, 6, plr)
-- Update the last shot time
lastShotTime = tick()
isRecharging = false
end)
RunService.Stepped:Connect(function ()
if tool.Charge.Value < MaxCharge and not isRecharging and tick() - lastShotTime >= RegenCooldown then
isRecharging = true
while tool.Charge.Value < MaxCharge and isRecharging do
tool.Charge.Value = tool.Charge.Value + ChargeRate
end
end
end)
btw this is a snippet of the script