- What do you want to achieve?
I want my tool to charge while I hold it down and then stop when I release the button
- What is the issue?
While holding down the button, everything works normally, but when I let go then the power continues and fills up again when I let go
Video:
- What solutions have you tried so far?
Roblox Documentation
– My code –
Server:
if action == "start" then
print("Starting power charge... Default Power: ", playerPowers[player])
humanoid.WalkSpeed = 8
while playerPowers[player] < maxPower do
if action == "start" then
playerPowers[player] = playerPowers[player] + powerIncreaseRate
print("Power: ", playerPowers[player])
PowerChargeEvent:FireClient(player, "update", playerPowers[player])
wait(0.1)
elseif action == "stop" then
break
end
end
if playerPowers[player] >= maxPower then
print("Full power")
end
elseif action == "stop" then
humanoid.WalkSpeed = 16
playerPowers[player] = 0
PowerChargeEvent:FireClient(player, "stop")
RockAttackEvent:FireClient(player, playerPowers[player])
print("Charging stopped")
end
end)
Client:
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
PowerChargeEvent:FireServer("start")
showPowerChargeUI()
ChargeTrack = humanoid:LoadAnimation(ChargeAnim)
ChargeTrack.Priority = Enum.AnimationPriority.Action3
ChargeTrack.Looped = true
ChargeTrack:Play()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
PowerChargeEvent:FireServer("stop")
if ChargeTrack then
ChargeTrack:Stop()
end
hidePowerChargeUI()
AttackTrack = humanoid:LoadAnimation(AttackAnim)
AttackTrack.Priority = Enum.AnimationPriority.Action3
AttackTrack.Looped = false
AttackTrack:Play()
end
end)