Part.Touched wont work

So in my game i have a growing (0.9 studs) black hole which is supposed to damage on touch but it only damages players on the edge of the part and if you’re inside the part you don’t take any damage at all.

i am completely lost.

local Db = {}
local DbTime = 0.25

BlackHole.Touched:Connect(function(Hit)
	if Hit.Parent then
		if Hit.Parent:FindFirstChild("Humanoid") then
			if Db[Hit.Parent] ~= true then

				Db[Hit.Parent] = true

				task.delay(DbTime, function()
					if Hit.Parent then
						Db[Hit.Parent] = false
					end
				end)

				Hit.Parent:FindFirstChild("Humanoid").Health -= 5
				local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

				if Player then
					
				end
			end
		end
	end
end)

i should probably add that it worked before

1 Like

I don’t see where this is defined. if Hit.Parent then – this is redundant
You’re storing Hit.Parent as a key in Db, but never removing it – Possible Memory Leak
Other than that I don’t see a problem.

im leaving out most of the script

this is just the part i suspect to be the issue

Is because of “.Touched” and how it works, touched will fire when you touch it and not if you are currently touching, a solution for you would be use a loop that check all the part inside the blackhole

edit:
if you want I make this code for you

local Players = game:GetService("Players")

local BlackHole = script.Parent

local Db = {}
local DbTime = 2

while true do
	
	for Index, Hit in pairs(workspace:GetPartsInPart(BlackHole)) do
		
		local Humanoid = Hit.Parent and Hit.Parent:FindFirstChildOfClass("Humanoid")
		if not Humanoid then continue end
		
		if Db[Humanoid] then continue end
		Db[Humanoid] = true
		
		task.delay(DbTime, function()
			Db[Humanoid] = nil
		end)
		
		Humanoid.Health -= 5
		
		local Player = Players:GetPlayerFromCharacter(Hit.Parent)
		
		if Player then
			
		end
		
	end
	
	task.wait()
	
end

.Touched will only work with physical movement, which is probably why it I assume stops working after the player is completely inside the black hole?

Try having workspace:GetPartsInPart inside a loop, and a for loop for going through the parts table

alright i’ll try that, i’ll let you know if it works

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