The “(function(variable))” in particular causes the “Attempt to connect failed: Passed value is not a function” error alongside making the parent be interperated as the part, which could work in my case but still contains the error.
local function getHitted(part, parentalplayer) -- parentalplayer comes out as nil
print(part)
print(parentalplayer)
end
hitbox.Touched:Connect(getHitted, (ParentalPLayer)) -- Connects the getHitted function and attempts to pass a variable after the bracket.
local function getHitted(part, parentalplayer)
print(part)
print(parentalplayer)
end
hitbox.Touched:Connect(function(part)
local parentalplayer = game.Players:GetPlayerFromCharacter(part.Parent)
getHitted(part, parentalplayer)
end)
Very nice, although I did originally hold off on this idea due to the idea of a function in a function (the full code had the :connect(function) inside another function) seeming quite inefficient… is it? Could you lend me some of your wisdom?
Functions within functions (also known as nested functions or closures) are a common practice in many programming languages. So don’t worry about it, it’s fine.