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

How does this script get arguments for its Function parameters?

Asked by 5 years ago

This script is from an example on the roblox wiki, and I'm wondering how the function finds arguments for the parameters hitPart and partDistance?

local maxDamage = 100    -- maximum possible damage. could also be based off of the Humanoid's MaxHealth

local explosion = Instance.new("Explosion")
explosion.DestroyJointRadiusPercent = 0 -- neck welds won't be destroyed
explosion.BlastRadius = 8

explosion.Hit:connect(function(hitPart, partDistance)
    local humanoid = hitPart.Parent and hitPart.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local distance_factor = partDistance / explosion.BlastRadius    -- get the distance as a value between 0 and 1
        distance_factor = 1 - distance_factor                         -- flip the amount, so that lower == closer == more damage
        humanoid:TakeDamage(maxDamage*distance_factor)                -- 0: no damage; 1: max damage
    end
end)

explosion.Parent = workspace

1 answer

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

If you take a look at the docs, you can see that Explosion.Hit has two parameters: part and distance.

Hope this helps.

Ad

Answer this question