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

Why Won't my troll barrel work?

Asked by 8 years ago

I decided to make a barrel that makes you fly away when you touch it at the right speed. *It is in a Regular script. *The error is "Script:4: attempt to compare userdata with number" This is the script:

local Barrel = script.Parent.Union

function Explode(Part)
    if Part.Velocity <= 1 then
        local expl = Instance.new("Explosion")
        expl.BlastPressure = 99999999
        expl.BlastRadius = 100
        expl.DestroyJointRadiusPercent = 0

    end
end

Barrel.Touched:connect(Explode)
0
Accidentally put in the wrong speed. It is suppost to be 16 ADeadlyGuest4 62 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

The Velocity property of Part is a Vector3 value (userdata), you can't directly compare it to a number.

The Vector3 has 3 properties, X, Y and Z.

Let's assume you wanted to change the Y value.

local Barrel = script.Parent.Union

function Explode(Part)
    if Part.Velocity.Y <= 1 then -- Velocity.Y
        local expl = Instance.new("Explosion")
        expl.BlastPressure = 99999999
        expl.BlastRadius = 100
        expl.DestroyJointRadiusPercent = 0

    end
end

Barrel.Touched:connect(Explode)
0
Is there a way to measure the velocity of an object from any angle without doing advanced calculations ADeadlyGuest4 62 — 8y
Ad

Answer this question