I want to be able to make a pressure plate that detects if a player’s character touched it or a block touched it and activate a tween to shift its size down. I also want it to shift its size back to normal but I have this bug where the pressure plates “jiggles” when it detects collision of the character and the block.
Basically, you just need to add a debounce to the “Touched” event otherwise it’ll detect multiple of touches so fast but you only really need 1 to touch it. Also you can make a tween to go back again.
local tweenInfoDown = TweenInfo.new(
.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
true, -- this bring back the tween to the original state aka "Up"
0
)
local TS = game:GetService("TweenService")
local plate2 = plate1.Parent.Parent.PressurePlate2
local block = game.Workspace.Rooms.Room2.Block
db = false
local TweenInfo = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,true,0)
local TSDown = TS:Create(plate1, TweenInfo, {Size = Vector3.new(4, 0, 4})
plate1.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") ~= nil then
if not db then
db = true
TSDown:Play()
TSDown.Completed:Wait()
task.wait(2.5)
db = false
end
end
end)
Basically what it’ll do is when it touches it’ll stop the other touching parts and then it’ll play the tween [it goes up and down] and then wait after a time and the debounce will stop.
You don’t ever use “Wait()” dont argue with the deprecated version of task.wait(). You’d always choose task.wait() over wait(). It doesn’t lags or “Crash” the game.