How to check if the player is touching & not touching a part?

Title says it all. I need to know if when a player touches & not touches a part for my jail system. I want it so if the player is not touching a part, it teleports him back to an area where he is until his jail counter is done. Heres the code so far:

local DSS = game:GetService("DataStoreService")

local Players = game:GetService(“Players”)
local JailDataStore = DSS:GetDataStore(“JailData”)

Players.PlayerAdded:Connect(function(player)
local Part = game.Workspace.prisonBorder
local Parts = Part:GetTouchingParts()
local inJail = player:WaitForChild(“Data”):WaitForChild(“inJail”)

while true do
	
	
	end
	
	
	
end

end)

I’m just stumped.

1 Like

You can try something with this:

local part = "The part to get touched"
local region = Region3.new(part.Position+(part.Size/2), part.Position-(part.Size/2))
local touchingParts = workspace:FindPartsInRegion3(region)
1 Like

how would I detect it not touching?

1 Like
local player = "The player"
local touching = false

for v, part in pairs(touchingParts) do
    if part.Parent == player.Character then
        touching = true
    end
end
2 Likes
if inJail == true and not touchingParts then

so this would be it?

1 Like

See @ancadejo10 's reply.

1 Like

local DSS = game:GetService(“DataStoreService”)
local Players = game:GetService(“Players”)
local JailDataStore = DSS:GetDataStore(“JailData”)

Players.PlayerAdded:Connect(function(player)
local part = game.Workspace.prisonBorder
local inJail = player:WaitForChild(“Data”):WaitForChild(“inJail”)
local region = Region3.new(part.Position+(part.Size/2), part.Position-(part.Size/2))
local touchingParts = workspace:FindPartsInRegion3(region)
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)
local RootPart = Character:WaitForChild(“HumanoidRootPart”)
local touching = false

while true do
	wait(0.4)
	for v, part in pairs(touchingParts) do
		if part.Parent == player.Character then

			touching = true
		elseif touching == false then
			if player.Data.inJail.Value == true then
				RootPart.CFrame = CFrame.new(149.87, 150.923, 2369.18)
			end

		end
	end
end

	
	
	
end)

doesnt work

1 Like
while true do
	wait(0.4)
    local touching = false
	for v, part in pairs(touchingParts) do
		if part.Parent == player.Character then
			touching = true
		end
	end

	if player.Data.inJail.Value == true and not touching then
		RootPart.CFrame = CFrame.new(149.87, 150.923, 2369.18)
	end
end
1 Like

part.Parent = Player.Character
touchingParts = hitbox? (like for combat system)

so it works like this?:

for v, part in pairs(rootpart:GetChildren()) do
	if v.Name == "Hitbox" and part.Parent == player.Character then
		touching = true
	end
end
1 Like
local hitbox = serverstorage.CombatHitboxExample:Clone()
hitbox.Parent = rootpart
hitbox.CFrame = rootpart.CFrame + (rootpart.CFrame.lookVector * 1.5) 

--continie

local region = Region3.new(hitbox.Position+(hitbox.Size))
local touchingParts = workspace:FindPartsInRegion3(region)

	for i,v in pairs(touchingParts) do
		local enemy = v.Parent
		if enemy then
			local humanoid = enemy:FindFirstChild("Humanoid")

			if humanoid then
				--doing something
				end
			end
		end
	end

but its didnt work :sleepy:

i cant believe no one are answering what the hell

1 Like