Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Workspace.Part.Damage:21: invalid argument #1 to 'find' (table expected, got Instance)?

local waitTime = 0.2
local Debounce = false
local Char = {}

local function Touched(hit)
	if not Debounce then
		if not hit.Parent:FindFirstChild("Humanoid") then return end
		Debounce = true
		hit.Parent:SetAttribute("Damage", true)
		table.insert(Char, hit.Parent)
		wait(waitTime)
		Debounce = false
	end
end

local function TouchEnded(hit)
	if not Debounce then
		if not hit.Parent:FindFirstChild("Humanoid") then return end
		Debounce = true
		hit.Parent:SetAttribute("Damage", false)
		table.remove(Char, table.find(hit.Parent))
		wait(waitTime)
		Debounce = false
	end
end

script.Parent.Touched:Connect(Touched)
script.Parent.TouchEnded:Connect(TouchEnded)

while task.wait(waitTime) do
	if table.getn(Char) > 0 then
		for _, Plr in pairs(Char) do
			if Plr:GetAttribute("Damage") == true then
				Plr.Humanoid:TakeDamage(10)
			end
		end
	end
end

help

1 answer

✓ Accepted answer

table.find takes at least 2 arguments. First the table, then the value you're looking for. It only returns the first occurrence, so you should make sure there's only one. On line 10:

if table.find(Char, hit.Parent) == nil then
	table.insert(Char, hit.Parent)
end

(table.find returns nil if the value was not found.)

Line 21:

table.remove(Char, table.find(Char, hit.Parent))

This discussion is preserved as it was. New answers, comments, and votes are closed.