Problem with tables

Hi, I have made lava that works like jump pad and deals damage, but I have problem with it; It sometimes deals double or even triple damage. I made debounce table that makes lava unable to deal double or triple damage to you, but it still doing it.

Here’s my code

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)
local runService = game:GetService("RunService")
while wait() do
	for index, part in pairs(workspace:FindPartsInRegion3(region, nil, 5000)) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			if part.Parent.Humanoid.Health ~= 0 then
				if not table.find(damagePlayers, part.Parent) then
					table.insert(damagePlayers, part.Parent)
					part.Parent.Humanoid:TakeDamage(25)
					wait()
					part.Parent.Humanoid.JumpPower = 100
					part.Parent.Humanoid.Jump = true
					wait(0.1)
					part.Parent.Humanoid.JumpPower = 50
					wait(0.3)
					table.remove(damagePlayers, table.find(damagePlayers, part.Parent))
				end
			end
		end	
	end
end

Please reply if you know what’s the issue

You cannot insert an object into a table, instead, try inserting the name of the object :wink:

Tried this, getting error “Unable to cast Value to object”

On which line?

20chars
20chars

Line 11; if not table.find(damagePlayers, game.Players:GetPlayerFromCharacter(part.Parent.Name)) then

Why use GetPlayerFromCharacter? Try using part.Parent.Name instead.

Here are ways I tried: part.Parent.Name, part.Parent and getplayerfromcharacter

What error do you get when you use part.Parent.Name? Also make sure you use it every time you change the table.

There is no error, I’m just taking more damage sometimes

Try making your debounce bigger.

You mean longer? Nah, I can even put 10 seconds, and after that 10 seconds I will take more damage

Increase the wait(0.3), that should work. If not then make sure you insert the name of the player and check for that name before damaging the player. Also your hitbox might be to large.

Read the script, the table is checked, its being inserted and removed after damaging player

I know but you use part.Parent.Name, right? Could you show the script you are using?

Its the exact same script that is in the post

So you are not using the name of the player, but the instance of his character? Try using the name of the player as I said above.

Yeah I tried using it, STILL same effect

And you tried increasing the debounce? Can you show the slightly modified script please?

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)
local runService = game:GetService("RunService")
print(region)
while wait() do
	for index, part in pairs(workspace:FindPartsInRegion3(region, nil, 5000)) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			if part.Parent.Humanoid.Health ~= 0 then
			if not table.find(damagePlayers, part.Parent.Name) then
				table.insert(damagePlayers, part.Parent.Name)
				print(damagePlayers[1])
				part.Parent.Humanoid:TakeDamage(25)
				wait(0.3)
				table.remove(damagePlayers, table.find(damagePlayers, part.Parent.Name))
				end
			end
		end	
	end
end


You can try fixing lava on a baseplate, just copy script, put in ServerScriptService and make lava object