Jiggling Pressure Plate

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.

Demonstration in the video:
https://gyazo.com/b560f49ac01b91362ce54cec8bc161dc

My script:

local plate2 = plate1.Parent.Parent.PressurePlate2

local block = game.Workspace.Rooms.Room2.Block

local TS = game:GetService("TweenService")
local tweenInfoDown = TweenInfo.new(
	.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local tweenPropDown = {
	Size = Vector3.new(4, 0, 4)
}

local tweenDown = TS:Create(plate1, tweenInfoDown, tweenPropDown)

local tweenInfoUp = TweenInfo.new(
	.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local tweenPropUp = {
	Size = Vector3.new(4,1,4)
}

local tweenUp = TS:Create(plate1, tweenInfoUp, tweenPropUp)

plate1.Touched:Connect(function(part)
	
	local character = part.Parent

	if character or part.Name == block.Name then
		tweenDown:Play()
	end
end)

plate1.TouchEnded:Connect(function()
	tweenUp:Play()
end)

I haven’t tried any solutions so far because I couldn’t figure out one really.

P.S. I might not be able to respond until tomorrow because I’m really busy.

1 Like

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
)
1 Like
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)
3 Likes

Could you explain to me how this new code works? I’m not very familiar with debounces.

1 Like

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.

1 Like

I’ve read the code for a bit when I came across task.wait() I have never honestly seen this method… What does it do exactly?

1 Like

It just like “wait()” but better because it has a less delay than the original wait().

1 Like

But what exactly was the purpose of adding task.wait() to the code? If I had to guess, I think it could the crash the server.

1 Like

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.

2 Likes