I want to make it so players can’t spam a proximityprompt or a button that’s only supposed to be played once. I’ve tried to make it so as soon as it’s clicked, it gets disabled, but the players in my game figured out they can spam click the interaction with an autoclicker and mess up the game. How can I prevent players from spamming an interaction?
do this
local ClickDetectorIns = script.Parent.ClickDetector
local Cooldown = false
local Duration = 1 -- duration in seconds
ClickDetectorIns.MouseClick:Connect(function()
if Cooldown == false then
Cooldown = true
-- your script here
task.wait(Duration)
Cooldown = false
end
end)
Would this work with a proximityprompt aswell?
yes… it works with everything…
local Prompt = script.Parent.ProximityPrompt
local Cooldown = false
local Duration = 1 -- duration in seconds
Prompt.Triggered:Connect(function()
if Cooldown == false then
Cooldown = true
-- your script here
task.wait(Duration)
Cooldown = false
end
end)
I’ve tried it but it still does not work. I tested it with an autoclicker and players would still be able to spam the interaction
can you show me your script? so i can see what’s wrong
local TweenService = game:GetService("TweenService")
local model = script.Parent
local Door = model.Parent.Parent.Door
local tweenInfo = TweenInfo.new(1)
local GoalOpen = {}
local GoalClose = {}
GoalOpen.CFrame = Door.CFrame * CFrame.new(Door.Size.X, 0, 0)
GoalClose.CFrame = Door.CFrame
local TweenOpen = TweenService:Create(Door, tweenInfo, GoalOpen)
local TweenClose = TweenService:Create(Door, tweenInfo, GoalClose)
local NumberScreen = script.Parent.Parent.Parent.NumberScreen.SurfaceGui.TextLabel
local ClickDetectorIns = script.Parent.ClickDetector
local Cooldown = false
local Duration = 5 -- duration in seconds
ClickDetectorIns.MouseClick:Connect(function()
if Cooldown == false then
Cooldown = true
function onClicked(playerWhoClicked)
script.Parent.ClickDetector.MaxActivationDistance = 0
NumberScreen.Parent.Parent.PowerUp:Play()
script.Parent.Transparency=1
wait(.1)
script.Parent.Transparency=0
TweenOpen:Play()
script.Parent.Parent.Parent.Door.sliding_door_open:Play()
script.Parent.Parent.Parent.NumberScreen.Color = Color3.new(0.54902, 0.54902, 0.54902)
script.Parent.Parent.Parent.NumberScreen.SurfaceGui.Enabled = true
wait(1)
NumberScreen.Text = "2"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
NumberScreen.Text = "1"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
NumberScreen.Text = "0"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
script.Parent.Parent.Parent.NumberScreen.SurfaceGui.Enabled = false
NumberScreen.Text = "3"
script.Parent.Parent.Parent.NumberScreen.Color = Color3.new(0.105882, 0.105882, 0.105882)
TweenClose:Play()
NumberScreen.Parent.Parent.PowerDown:Play()
script.Parent.Parent.Parent.Door.sliding_door_close:Play()
script.Parent.ClickDetector.MaxActivationDistance = 16
end
task.wait(Duration)
Cooldown = false
end
end)
script.Parent.ClickDetector.MouseClick:connect(onClicked)
the cooldown bool wasn’t inside the onClicked function
try this
local TweenService = game:GetService("TweenService")
local model = script.Parent
local Door = model.Parent.Parent.Door
local tweenInfo = TweenInfo.new(1)
local GoalOpen = {}
local GoalClose = {}
GoalOpen.CFrame = Door.CFrame * CFrame.new(Door.Size.X, 0, 0)
GoalClose.CFrame = Door.CFrame
local TweenOpen = TweenService:Create(Door, tweenInfo, GoalOpen)
local TweenClose = TweenService:Create(Door, tweenInfo, GoalClose)
local NumberScreen = script.Parent.Parent.Parent.NumberScreen.SurfaceGui.TextLabel
local ClickDetectorIns = script.Parent.ClickDetector
local Cooldown = false
local Duration = 5 -- duration in seconds
function onClicked(playerWhoClicked)
if Cooldown == false then
Cooldown = true
script.Parent.ClickDetector.MaxActivationDistance = 0
NumberScreen.Parent.Parent.PowerUp:Play()
script.Parent.Transparency=1
wait(.1)
script.Parent.Transparency=0
TweenOpen:Play()
script.Parent.Parent.Parent.Door.sliding_door_open:Play()
script.Parent.Parent.Parent.NumberScreen.Color = Color3.new(0.54902, 0.54902, 0.54902)
script.Parent.Parent.Parent.NumberScreen.SurfaceGui.Enabled = true
wait(1)
NumberScreen.Text = "2"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
NumberScreen.Text = "1"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
NumberScreen.Text = "0"
NumberScreen.Parent.Parent.BeepNoise:Play()
wait(1)
script.Parent.Parent.Parent.NumberScreen.SurfaceGui.Enabled = false
NumberScreen.Text = "3"
script.Parent.Parent.Parent.NumberScreen.Color = Color3.new(0.105882, 0.105882, 0.105882)
TweenClose:Play()
NumberScreen.Parent.Parent.PowerDown:Play()
script.Parent.Parent.Parent.Door.sliding_door_close:Play()
script.Parent.ClickDetector.MaxActivationDistance = 16
task.wait(Duration)
Cooldown = false
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
2 Likes
Thanks it works! There’s a small issue where if you try to spam click it after it still keeps making the button noise but I know how to fix the issue
3 Likes