How to create a floor button

I believe this is what is after Region3: OverlapParams

3 Likes

I’ll try to use that, thanks!!

1 Like

Can you post how you set this up? I’m curious how to use getpartsinpart in a way that is similar to touched. Do you have to just use an endless loop to keep checking or is there a way to set up a triggered connection?

I am trying to figure this out right now.
If you want to help me, you are welcome !

Well, I have done this with a looped interval query, but that does not seem like a desirable way to do it. It doesn’t seem efficient to keep checking something whether or not it has changed.

The touched event is fine.

local players = game:GetService("Players")
local button = workspace.Button
local debounce = false

button.Touched:Connect(function(hit)
	if debounce then
		debounce = false
		task.wait("5")
		return
	end
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		debounce = true
		local player = players:GetPlayerFromCharacter(hit.Parent)
		print(player.Name, " touched the button!")
	end
end)

yeah but it fires many times when only pressed once and does not tell me when it stops being pressed…

It works fine till it doesn’t. What if your player’s tool or a part within an accessory they’re wearing touches the part first, in which case it won’t find the humanoid but will trigger the debounce and your button is now dead for x seconds.

This version won’t, I’ve added a debounce which prevents the function from being executed too often (in this case the timeout is set to 5 seconds).

Right and you get false positives and a dead button for an interval.

You can perform a check on hit itself, to make sure it’s named “Left Leg” or some other body part of the character.

well it does…
I tested it and it fired 7 times

So i would like to know how to use
:GetPartsInPart(PartInstance part, OverlapParams overlapParams)
and i cant find how ;-;

There are many ways to make it work better, but its still not entirely predictable in my experience. One way is to make a trigger part and wait for only the humanoidrootpart to touch it(throw out all other triggers), then debounce. But then you have the problem of multiple players and having to account for more than one player needing to activate the button at the same time(or close to it). You could make a table of player who touched it and debounce per player, etc and etc. But there has to be a better way, no?

This forum post should have enough information:

1 Like

It returns a table of parts that are within the part. But then you’ll have the problem of how often you check to see if a player part is in there.

You don’t want a game full of buttons polling in infinite loops looking for players.

I was gonna say that.
If tool of a Player Touches, you can still get Player, by checking Parent, until you get Humanoid, Or if you don’t want Tool to work; than don’t flip the debounce on Tool…
I’ve used Touched and .magnitude, but don’t know Region3, and Yes, I’ve read there is a new Method for Region, also…

.Magnitude is pretty-well the same as Region, except a sphere (or a cylinder of infinite height, if you strip the Y value), instead of a box…

1 Like

Like I mentioned a simple name check on the hit variable should prevent that.

I know you got the answer already, but in case you want an example I made a little resource 2 weeks ago that does that using OverlapParams.

Grapple/Box Grabbing System

I’m pretty sure doing the checks constantly wouldn’t be good, so to avoid harming performance I start the checks either when a box is placed or when the player touches the pad, and after the area becomes clear the checks stop, so as long as you don’t leave too much boxes on the pads it shouldn’t cause any performance issues.

I found a solution!!
For the lag issues i will just disable the buttons of the rooms the player is not in.(Single player game)
Here is it in studio:
image
image

And here is the script:

local TweenService = game:GetService("TweenService")
-----000000000-----
local Collider = script.Parent.Collider
local Value = script.Parent.IsPressed
local Pusher = script.Parent.Pusher
-----000000000-----
local OriginalPosition = Pusher.Position
-----
local GoalPressed = {}
GoalPressed.Position = OriginalPosition - Vector3.new(0,0.25,0)
-----
local GoalReleased = {}
GoalReleased.Position = OriginalPosition
-----
local TweenInformation = TweenInfo.new(
	0.25,						-- Duration of the tween in seconds
	Enum.EasingStyle.Sine,		-- Kind of easing to apply
	Enum.EasingDirection.In,	-- Direction of the easing
	0,							-- Times the tween is repeated
	false						-- If the tween is gonna reverse
)
-----
local PressTween = TweenService:Create(Pusher, TweenInformation, GoalPressed)
local ReleaseTween = TweenService:Create(Pusher, TweenInformation, GoalReleased)
-----000000000-----
while wait(0.2) do
	local PartsTouching = game.Workspace:GetPartsInPart(Collider)
	if #PartsTouching ~= 0 then
		print("Press")
		Value.Value = true
		PressTween:Play()
	elseif #PartsTouching == 0 then
		print("Release")
		Value.Value = false
		ReleaseTween:Play()
	end
end