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 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.
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