Problem with tables

You can insert objects to tables… try it out

Yeah, but do you know what’s the issue of it? The table is created, there is an if statement that checks if player is not in table, but you still take more damage.

Can I ask why you are using a region3 and constantly checking in a while loop for all the parts inside it? You could just use the .Touched event of a part.

.Touched not always detecting if the part was touched, that results in player can stand on lava

Try making your hitbox a bit higher than the lava. (Invisible and cancollide to false).

Its NOT a hitbox problem, its tables or loops problem

When using the touched event you can cut down on loops used. But if you don’t want to use it, try printing whenever you add/remove something from a table and it’s contents so that you know what’s going on inside it at all times.

This would help with touches not detecting sometimes as more bodyparts make contact with the hitbox and not only the feet of the character.

I tried that, and it still not detects sometimes, touched event is just broken sometimes

I know what’s the issue!!! Checking table is in the for loop, so it will never find player in table, How can I send data from for loop to while loop?

Is there any particular reason you’re using tables as a list instead of just a dictionary? This is simplified a lot by just indexing the table with the humanoid instead of iterating over the list.

local damagePlayers = {}

local min = workspace.LavaWithCollision.Position - (.5 * workspace.LavaWithCollision.Size) 
local max = workspace.LavaWithCollision.Position + (.5 * workspace.LavaWithCollision.Size) 
local region = Region3.new(min, max)

while wait() do
	for index, part in pairs(workspace:FindPartsInRegion3(region, nil, 5000)) do
		local humanoid = part.Parent:FindFirstChild("Humanoid")

		if humanoid and humanoid.Health > 0 then
			if not damagePlayers[humanoid] then
				damagePlayers[humanoid] = true

				coroutine.wrap(function()
					humanoid:TakeDamage(25)
					
					wait()

					humanoid.JumpPower = 100
					humanoid.Jump = true

					wait(0.1)

					humanoid.JumpPower = 50

					wait(0.3)

					damagePlayers[humanoid] = nil
				end)()
			end
		end	
	end
end

you’ll find too that the waits for the jump effect will cause the checks to get delayed if multiple players are involved. Wrapping the yielding sections in a coroutine helps avoid that.

2 Likes

Thanks for help! I’ll try this script, Can you send me link to where can I learn coroutines?

There are probably a few resources that aren’t Roblox specific if you check google, but there are some community tutorials too:

https://www.lua.org/pil/9.1.html

They can be super useful when used properly!

2 Likes