Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote Event, Cooldown won't work, why?

Hewwo, I have a question.

Everytime I click the Part, it won't have a cooldown..(You can click it as much as you want) I would be grateful for help. Thanks!

--script

local part = script.Parent
local clickd = script.Parent.ClickDetector

local berrysLeft = script.Parent.BerryLeft
local berryAmount = script.Parent.BerryAmount

local rep = game:GetService("ReplicatedStorage")
local remote = rep.Remotes.ClickBerrys

local deBerry = 1

local debounce = false

local getClickRemote = rep.TestRemote.ChangeValue
local getClickValueRemote = rep.TestRemote.getChangedValue

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		
		local CollectingSpeed = player.Skills.CollectingSpeed
		CollectingSpeed.Changed:Connect(function(changed)
			print(CollectingSpeed.Value)
		end)
		
		clickd.MouseClick:Connect(function(clicked)

			if not debounce then
				debounce = true
			
				berrysLeft.Value = berrysLeft.Value - deBerry
				part.Size = part.Size + Vector3.new(0,-0.25,0)
				
				--

				local deb = false
				getClickValueRemote.OnServerEvent:Connect(function(player, CollectingSpeedV)
					if deb == false then
						debounce = true
						
						wait(CollectingSpeedV)	--wait Amount to Click again
						debounce = false
					end
				end)
				
				--

				wait()
				debounce = false
			end
		end)
	end)
end)

1 answer

✓ Accepted answer

I think your problem is that your using OnServerEvent ( which is an entirely different code block ) meaning that the wait WONT transfer over, to fix this, do OnServerEvent outside of your .MouseClick function and make a variable for debounce.

like so:

local part = script.Parent
local clickd = script.Parent.ClickDetector

local berrysLeft = script.Parent.BerryLeft
local berryAmount = script.Parent.BerryAmount

local rep = game:GetService("ReplicatedStorage")
local remote = rep.Remotes.ClickBerrys

local deBerry = 1

local debounce = false
local DebWait = 1 -- set a default of one

local getClickRemote = rep.TestRemote.ChangeValue
local getClickValueRemote = rep.TestRemote.getChangedValue

getClickValueRemote.OnServerEvent:Connect(function(player, CollectingSpeedV)
   DebWait = CollectingSpeedV
   print("The current debounce is: " .. DebWait) -- for debugging
end)

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)

        local CollectingSpeed = player.Skills.CollectingSpeed

        CollectingSpeed.Changed:Connect(function(changed)
            print(CollectingSpeed.Value)
        end)

        clickd.MouseClick:Connect(function(clicked)

            if not debounce then
                debounce = true

                berrysLeft.Value = berrysLeft.Value - deBerry
                part.Size = part.Size + Vector3.new(0,-0.25,0)

                wait(DebWait)
                debounce = false
            end
        end)
    end)
end)

16 comments

0

I can't click the part now.

0

any errors?

0

It's working now. I refreshed the page and you changed something. Thank you so much :3

0

oh alright, your welcome. Accept it as your answer since it worked so other people know it's solved.

0

yes

0

Im new, how can i do this?

0

you press 'accept answer' at the bottom of the question ( or page ).

0

I'm sorry to bother you even more, but I really can't find it...

0

its right under the comment box, don't worry, it's not a problem if you can't find it.

0

There is just "Edit, Remove and Report" :(

0

its under my answer, not your question.

0

There is just "Report"

0

no idea, doesn't matter anyways it's okay if you find out how then you can do it not a big deal, anyways have fun scripting.

0

Thank you.:3

1

i'll accept for you

1

Thanks, kirda.

This discussion is preserved as it was. New answers, comments, and votes are closed.