Я пытаюсь преобразовать свою безымянную функцию, чтобы она лучше работала с использованием ООП, и у меня возникли некоторые трудности, поскольку я полагался на определенную область. Любые предложения, старый и новый код ниже:
СТАРЫЙ КОД - РАБОТАЕТ
for _,portal in pairs(script.Parent:GetChildren())do
if portal:IsA("Script") then continue end
portal.Touched:Connect(function(part)
local HRP = part.Parent:FindFirstChild("HumanoidRootPart")
if not HRP then return end
local DestinationName = portal:FindFirstChildOfClass("Attachment").Name
local Destination = script.Parent:FindFirstChild(DestinationName):FindFirstChild(portal.Name)
HRP.CFrame = Destination.WorldCFrame
end)
end
НОВЫЙ КОД - ОШИБКИ OBVS
local function portalTouched(part,portal)
local HRP = part.Parent:FindFirstChild("HumanoidRootPart")
if not HRP then return end
local DestinationName = portal:FindFirstChildOfClass("Attachment").Name
local Destination = script.Parent:FindFirstChild(DestinationName):FindFirstChild(portal.Name)
HRP.CFrame = Destination.WorldCFrame
end
for _,portal in pairs(script.Parent:GetChildren())do
if portal:IsA("Script") then continue end
portal.Touched:Connect(portalTouched(portal))
end
Проблема с подключением функций к событиям заключается в том, что вы не можете передать какие-либо дополнительные параметры. Как мне обойти эту проблему? Любые и все предложения приветствуются!