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

Why does it say unable to cast value to object?

Asked by
Jexpler 63
5 years ago

Here is my script:

local region = Region3.new(Vector3.new(script.Parent.Reg1.Position), Vector3.new(script.Parent.Reg2.Position))

while true do
    wait()
    local touching = game.Workspace:FindPartsInRegion3(region, 1000)
    for i,v in pairs(touching) do
        if v.Parent:FindFirstChild('Humanoid') and v.Parent:FindFirstChild("HInfect") then
            local number = math.random(1,10)
            if number == 1 then
                v.Parent.HInfect:Destroy()
            else
                v.Parent.Humanoid:TakeDamage(v.Parent.Humanoid.Health)
            end
        end
    end
end

1 answer

Log in to vote
3
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Because the 2nd parameter is a model or part the function will ignore, but you passed a number I'm assuming you want this to be the maxParts parameter.

If you're not gonna ignore any parts, set the parameter to nil:

local touching = workspace:FindPartsInRegion3(region, nil, 1000)
0
Thanks. Also for some reason it only gets the baseplate. Did I format the region3 wrong in the first line? Jexpler 63 — 5y
Ad

Answer this question