Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
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

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago

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))
Ad

Answer this question