Help With Cash On Hold

Hey I need help with this script. How can I make this script where it instead of clicking for cash I can just hold down and it gives Doge Coins (cash) with a 1 second delay.
Script:
local player = game.Players.LocalPlayer

script.parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()

	player.leaderstats.DogeCoins.Value = player.leaderstats.DogeCoins.Value  + 8
end)

end)

1 Like
script.parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        while game:GetService'UserInputService':IsMouseButtonPressed'MouseButton1' do
            player.leaderstats.DogeCoins.Value += 8
            wait(1)
        end
    end)
end)
3 Likes

For the hold down part you would just use ProximityPrompt

1 Like

Thanks! At first when I tried it it didn’t work, I just had to define player and make player a variable.

1 Like

Wait I have found a bug. When I hold it many I can just click and get it instantly.

Try adding a debounce

local debounce = true

script.parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        while game:GetService'UserInputService':IsMouseButtonPressed'MouseButton1' do
         if debounce == true then
            debounce = false
            player.leaderstats.DogeCoins.Value += 8
            wait(1)
            debounce = true
        end
    end)
end)

I got this error:
Workspace.TronixJohn.Porta-Miner 3000.LocalScript:13: Expected identifier when parsing expression, got ā€˜)’
Also this is the script I have right now:
local debounce = true
local player = game.Players.LocalPlayer

script.parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
while game:GetService’UserInputService’:IsMouseButtonPressed’MouseButton1’ do
if debounce == true then
debounce = false
player.leaderstats.DogeCoins.Value += 8
wait(1)
debounce = true
end
end)
end)

1 Like

I edited this in the comment

local debounce = true

    script.parent.Equipped:Connect(function(mouse)
    	mouse.Button1Down:Connect(function()
    		while game:GetService'UserInputService':IsMouseButtonPressed'MouseButton1' do
    			if debounce == true then
    				debounce = false
    				player.leaderstats.DogeCoins.Value += 8
    				wait(1)
    				debounce = true
    				end
    			end
    		end)
    end)
1 Like

You are missing a ā€œendā€

Edit: Original poster fixed their issue.

1 Like

When I hold it for less than a second it freezes my studio i got this: Script timeout: exhausted allowed execution time
My current script is this:local player = game.Players.LocalPlayer
local debounce = true

script.parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
while game:GetService’UserInputService’:IsMouseButtonPressed’MouseButton1’ do
if debounce == true then
debounce = false
player.leaderstats.DogeCoins.Value += 8
wait(1)
debounce = true
end
end
end)
end)

You gotta put the wait(1) outside of the debounce check, otherwise the loop will run without a timeout and freeze

1 Like

Actually you can probably just put a wait() outside instead

local debounce = true

script.parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		while game:GetService'UserInputService':IsMouseButtonPressed'MouseButton1' do
			if debounce == true then
				debounce = false
				player.leaderstats.DogeCoins.Value += 8
				wait(1)
				debounce = true
			end
			wait()
		end
	end)
end)
1 Like