Repeat action until button off

I’ve been working on a loop fire system and when you click the button and hold it repeat until you let go, and I was wondering how can I fix it up so it works because mine won’t work.

local player = game.Players.LocalPlayer


script.Parent.Parent.UI.Gameplay.Fire.MouseButton1Down:Connect(function()
	repeat
		local ray = Ray.new(player.Character.Head.CFrame.p, player.Character.Head.CFrame.LookVector * 1000)
		local hit, position = game.Workspace:FindPartOnRay(ray, player.Character.Head.Parent)
		local distance = (position - player.Character[game.ReplicatedStorage.LocalData.LocalSelected.Value].Fire.CFrame.p).magnitude
		game.ReplicatedStorage.Events:FindFirstChild(player.Name):FireServer("Activated", game.ReplicatedStorage.LocalData.LocalSelected.Value, hit, position, distance)
	until script.Parent.Parent.UI.Gameplay.Fire.MouseButton1Up
end)

You should use a debounce variable for a situation like this:

local isUp = true --variable to tell whether or not the mousebutton is up or down

script.Parent.Parent.UI.Gameplay.Fire.MouseButton1Up:Connect(function()
   isUp = true
end)

script.Parent.Parent.UI.Gameplay.Fire.MouseButton1Down:Connect(function()
    isUp = false
	repeat
		local ray = Ray.new(player.Character.Head.CFrame.p, player.Character.Head.CFrame.LookVector * 1000)
		local hit, position = game.Workspace:FindPartOnRay(ray, player.Character.Head.Parent)
		local distance = (position - player.Character[game.ReplicatedStorage.LocalData.LocalSelected.Value].Fire.CFrame.p).magnitude
		game.ReplicatedStorage.Events:FindFirstChild(player.Name):FireServer("Activated", game.ReplicatedStorage.LocalData.LocalSelected.Value, hit, position, distance)
	until isUp
end)