Awarding points when holding down mousebutton

Hey Aethuza here! I recently got into scripting and I’m working on script providing points.

So I made this script that awards you money when clicking on your MouseButton1, however I would like the script to give points over time as long as you hold down the button, example:

If held down award player with 10 points for each second. I have these two scripts:

Script 1:

local cooldown = false

script.Parent.MouseButton1Down:Connect(function()
	if cooldown == false then
		cooldown = true
	game.Workspace.Events.AddPoints:FireServer()
	script.Parent.Active = false
	wait(.02)
	script.Parent.Active = true
	cooldown = false
	end
end)

Script 2:

script.AddPoints.OnServerEvent:Connect(function(plr)

plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10 + plr.leaderstats.Prestige.Value

end)

script.Prestige.OnServerEvent:Connect(function(plr)

plr.leaderstats.Prestige.Value = plr.leaderstats.Prestige.Value +1

plr.leaderstats.Points.Value = 0

plr:LoadCharacter()

end)

Thank you in advance!

This is possible by using a while loop and MouseButton1Up.

When the MouseButton1Down event is fired, set a boolean variable to true.
Likewise, when MouseButton1Up is fired, set the boolean variable false.
The while loop inside will use this boolean as the condition.

For example:

--// Variables
local bool = false

--// Functions
function Down()
    bool = true
    while bool do
        --// Award the point
        wait(1)
    end
end

function Up()
    bool = false
end

--// Connections
script.Parent.MouseButton1Down:Connect(Down)
script.Parent.MouseButton1Up:Connect(Up)