Hi. I have managed to msg player when player clicks to get item if player already have that item in inventory but i have no idea how to add a cooldown on it instead of checking backpack.
Hope someone can help me change from this to cooldown timer for player (I would wish to have option to do it for all players and option for only player that have clicked. If not possible then only for player who clicked)
NOTE: I'm a compleete noob in scripting
function onClicked() do --for i=1, 1 do --while wait(5) do for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("Backpack") then if player:FindFirstChild("Backpack"):FindFirstChild("Blue Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Green Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Red Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Yellow Master Key") then local M = Instance.new("Hint") M.Parent = game.Workspace -- Don't edit or change this. M.Text = "You allredy own a Master Key" wait(3) -- Wait to change insert thing. M.Text = "You can only have 1 Master Key in your inventory" wait(3) -- Waits to change then Remove insert differ thing. M:Remove() else do ------HERE GOES VERRY HUGE SCRIPT end end end end end end end end end end -------------------------------------------------------------------- script.Parent.ClickDetector.MouseClick:Connect(onClicked)
hello, kexiGamer!
This just adds a debounce to your code!
local deb = false function onClicked() do if not deb then deb = true for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("Backpack") then if player:FindFirstChild("Backpack"):FindFirstChild("Blue Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Green Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Red Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Yellow Master Key") then local M = Instance.new("Hint") M.Parent = game.Workspace -- Don't edit or change this. M.Text = "You allredy own a Master Key" wait(3) -- Wait to change insert thing. M.Text = "You can only have 1 Master Key in your inventory" wait(3) -- Waits to change then Remove insert differ thing. M:Remove() else do ------HERE GOES VERRY HUGE SCRIPT end end end end end end end end end end wait(120) -- Cooldown deb = false end -------------------------------------------------------------------- script.Parent.ClickDetector.MouseClick:Connect(onClicked)
This Cooldown is called debounce
This script shows countdown:
local deb = false local CountdownTime = 120 -- You can change the countdown time =D -- Don't change above! local Countdown = CountdownTime local Text = script.Parent.Text function onClicked() do if not deb then deb = true for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("Backpack") then if player:FindFirstChild("Backpack"):FindFirstChild("Blue Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Green Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Red Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Yellow Master Key") then local M = Instance.new("Hint") M.Parent = game.Workspace -- Don't edit or change this. M.Text = "You allredy own a Master Key" wait(3) -- Wait to change insert thing. M.Text = "You can only have 1 Master Key in your inventory" wait(3) -- Waits to change then Remove insert differ thing. M:Remove() else do ------HERE GOES VERRY HUGE SCRIPT end end end end end end end end end else script.Parent.Text = "Can't click now, must wait: " .. Countdown .. " seconds!" wait(5) script.Parent.Text = Text end while Countdown > 0 do Countdown = Countdown - 1 end local Countdown = CountdownTime deb = false end -------------------------------------------------------------------- script.Parent.ClickDetector.MouseClick:Connect(onClicked)
Hope it helps!
Good Luck with your games!
I believe what you're looking for is debounce: https://wiki.roblox.com/index.php?title=Debounce
I added it into your script, hopefully this is what you want and it works out for you.
I also indented your code to make it look neater and see that you have unnecessary ends that don't add up at the end.
local buttonPressed = false function onClicked() do --for i=1, 1 do --while wait(5) do if not buttonPressed then buttonPressed = true for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("Backpack") then if player:FindFirstChild("Backpack"):FindFirstChild("Blue Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Green Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Red Master Key") or player:FindFirstChild("Backpack"):FindFirstChild("Yellow Master Key") then local M = Instance.new("Hint") M.Parent = game.Workspace -- Don't edit or change this. M.Text = "You allredy own a Master Key" wait(3) -- Wait to change insert thing. M.Text = "You can only have 1 Master Key in your inventory" wait(3) -- Waits to change then Remove insert differ thing. M:Remove() buttonPressed = false else do ------HERE GOES VERRY HUGE SCRIPT end end end end end end end -------------------------------------------------------------------- script.Parent.ClickDetector.MouseClick:Connect(onClicked)