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

How does this script get arguments for its Function parameters?

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

✓ Accepted answer

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

Hope this helps.

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