Hold for power either holding to much or starting 2/3 times in one click

So, i’m making a hold for power button for a football game, but the problem is that it stays holding i tried doing the loop inside the function but that made it worse i tried my firends help but the also couldn’t figure it out and i also want a faster way to get more power

local Player = game.Players.LocalPlayer

local down = false

local CanShoot = true
Player.PlayerGui.Controls.Shoot.MouseButton1Down:Connect(function()
	script.Power.Value = 30
	if workspace.Bools:FindFirstChild(Player.Name.."GK").Value ~= true then
		down = true
		CanShoot = false
	else
		local Idle = workspace.Animations.GKmove
		script.RemoteEvent:FireServer("GK")
	end
end)

Player.PlayerGui.Controls.Shoot.MouseButton1Up:Connect(function()
	if not CanShoot and workspace.Bools:FindFirstChild(Player.Name.."GK").Value == false then
		
		repeat 
			down = false
		until down == false

		if Player.PlayerGui.Controls.Left.Value == true then
			script.RemoteEvent:FireServer(true, script.Power.Value, "CurveLeft")
		else
			script.RemoteEvent:FireServer(true, script.Power.Value, "no")
		end

		if Player.PlayerGui.Controls.Right.Value == true then
			script.RemoteEvent:FireServer(true, script.Power.Value, "CurveRight")

		else
			script.RemoteEvent:FireServer(true, script.Power.Value, "no")
		end

		wait(2)

		Player.PlayerGui.Controls.Power.Visible = false

		script.Power.Value = 30
	end
	
	wait(3)
	CanShoot = true
end)

local function onInputBegan(input, _gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		script.Power.Value = 30
		if workspace.Bools:FindFirstChild(Player.Name.."GK").Value == false then
			down = true
			CanShoot = false
		else
			local Idle = workspace.Animations.GKmove
			script.RemoteEvent:FireServer("GK")
		end
	end
end

local function onInputEnded(input, _gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		if not CanShoot and workspace.Bools:FindFirstChild(Player.Name.."GK").Value == false then
			
			repeat 
				down = false
			until down == false

			if Player.PlayerGui.Controls.Left.Value == true then
				print("left")
				script.RemoteEvent:FireServer(true, script.Power.Value, "Curve")
			elseif Player.PlayerGui.Controls.Right.Value == true then
				script.RemoteEvent:FireServer(true, script.Power.Value, "CurveRight")
			elseif Player.PlayerGui.Controls.Right.Value == false and Player.PlayerGui.Controls.Left.Value == false then
				script.RemoteEvent:FireServer(true, script.Power.Value, "no")
			end

			wait(2)

			Player.PlayerGui.Controls.Power.Visible = false

			script.Power.Value = 30
		end
		wait(3)
		CanShoot = true
	end
end

local UIS = game:GetService("UserInputService")

game["Run Service"].RenderStepped:Connect(function()
	if down then
		if script.Power.Value < 100 then
			Player.PlayerGui.Controls.Power.Visible = true
			Player.PlayerGui.Controls.Power.MovingFrame.Size = UDim2.new((script.Power.Value / 100), 0, 1, 0)
			script.Power.Value += 1
			print(script.Power.Value)
			wait(0.02)
		elseif script.Power.Value >= 100 then
			script.Power.Value = 100
		end
	end
end)

UIS.InputBegan:Connect(onInputBegan)
UIS.InputEnded:Connect(onInputEnded)

ignore if the script is long

Probably should move this to #help-and-feedback:scripting-support.

sorry i’m new to the devforum and i’m not getting help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.