How to make a Part suck in the Player only when in hitbox?

Hello!!

I am currently working on a game, [Dont touch grass ;-;], and I have been having fun developing it with someone else as we both work together to make something great.

HOWEVER,

There is one issue.
There are hazardous areas, mostly consisting of pits or blades.
The thing is, the pits are fine. Just make the player fall through the world while the camera locks in place so it makes it look like they fall infinitely. But, the blades are the problem.
See, in the first area, the blades are fans that suck the player into them, ultimately killing them.

The problem?

It’s only going to suck them in if they’re in a specific area.
Image slightly explaining:


So, How would I do this? How would I put the Player in some sort of ‘queue’ that they are only added in when they touch the part/area, but they are removed from when they leave the part/area?

Any help is appreciated. I am willing to answer replies to give more information (thats relevant).

2 Likes

Well the best way to acomplish something like this IMO is to track the player using a method of debounce, but it almost sounds like you have part of it. My personal way to do this is to track the player position overall.

Now this kind of describes it but he is doing the opposite of what you want (he is making the part follow the player) so you can kind of reverse that logic and track the player position while they are in the area. But another issue that might arise is you don’t want to use CFrame, and yeah I get that some people don’t but CFrame is like a fact, CFrame and using world CFrame might take more code. However, its a garunteed outcome, I know the players CFrame realtive to world example is CFrame:ToObjectSpace and CFrame:ToWorldSpace.

1 Like

Could you add me on discord? I may be able to help you with this.

1 Like

Alright, thanks. I will look into this post and note down anything that will be of use.

Apologies, my discord is not up for chatting with people, it is mainly used for family members. (This is just my personal preference, maybe you can DM me here on the DevForum?)

Thank you SO MUCH! With this post, I managed to make something- Beforehand I was checking for players from the part, but now I can just check for the part from the players!

Heres the code: (If anyone else is having the same problem)

local service = game

local run_service = service:GetService("RunService")
local collection_service = service:GetService("CollectionService")

local character = service:GetService("Players").LocalPlayer.Character
local hrp = character:FindFirstChild("HumanoidRootPart")
local humanoid = character:FindFirstChildOfClass("Humanoid")

local velocity = script.LinearVelocity
local current = {}

function handler_()
	for i, PART in pairs(current) do
		local CLONE = velocity:Clone()
		local ATTACHMENT = Instance.new("Attachment")
		ATTACHMENT.Parent = hrp
		
		CLONE.Parent = ATTACHMENT
		CLONE.Attachment0 = ATTACHMENT
		CLONE.Enabled = true
		
		CLONE.VectorVelocity = PART:GetAttribute("Velocity") 
		CLONE.MaxAxesForce = PART:GetAttribute("MaxForce")
		
		coroutine.wrap(function()
			while task.wait() do
				local found = false
				local PARTS = workspace:GetPartBoundsInBox(hrp.CFrame, hrp.Size)
				for i, PART_ in pairs(PARTS) do
					if PART_ == PART then
						found = true  
					end
				end
				
				if found == false then
					local index = table.find(current, PART)
					table.remove(current, index)
					ATTACHMENT:Destroy() 
					break 
				end
			end
		end)()
	end
end 

run_service.Heartbeat:Connect(function(dt)
	local PARTS = workspace:GetPartBoundsInBox(hrp.CFrame, hrp.Size)
	for i, PART in pairs(PARTS) do
		 if collection_service:HasTag(PART, "Vacuum") then
			if not table.find(current, PART) then
				table.insert(current, PART) 
				handler_()
			end
		 end
	end
end)

May be a bit scuffed, but it works ! Thank you !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.