So boom, I’ve been working on a Connection Module that helps me write Connections easier for my game. I’ve recently ran into a problem where instead of it printing the actual Part I’m standing on, it prints all 3 Parts no matter what. I’m trying to fix this but I don’t understand what’s happening nor what I can do to fix it. Please help
My Code
-- Check {Connection} --
elseif ConnectionName == 'Touchdown' then
local BoundParts = ReceivedAsset:GetChildren()
-- For Statement {Getting BoundPart} --
for _,BoundPart in ipairs(BoundParts) do
if BoundPart:IsA('Part') then
-- Call Function {Create Hitbox} --
self:CreateHitbox(BoundPart)
end
end
----
-- Call Function {Create Touched Function} --
_ConnectionService:CreateConnection(ConnectionName,BoundParts,'Touched',function(TouchedPart)
local Character = TouchedPart.Parent
local GlobalPlayer = PlayerService:GetPlayerFromCharacter(Character)
----
-- Check {Finding Both Character & GlobalPlayer} --
if GlobalPlayer and Character then
if not Character:FindFirstChild('Football') then
-- For Statement {Getting BoundParts} --
for _,BoundPart in ipairs(BoundParts) do
if BoundPart.Name == 'HomeEndzone' then
print('Touched HomeEndzone')
elseif BoundPart.Name == 'AwayEndzone' then
print('Touched AwayEndzone')
elseif BoundPart.Name == 'Turf' then
print('Touched Turf')
end
end
end
end
end)
----
Where do you get your “RecievedAsset” variable? If I had to guess with no tests, you are passing all three possibilities into your script therefore passing all three events. I couldn’t exactly know for sure without running your scripts though-
-- Module Functions {Configuring Connections} --
function ConnectionService:CreateConnection(ConnectionName,SupportingParts,SignalType,CallBack)
if typeof(CallBack) ~= 'function' then
-- Output {Invalid Connection CallBack} --
warn('Invalid CallBack Connection ' .. ConnectionName)
return
end
----
-- Constants {Figuring SupportingParts} --
local SinglePart = typeof(SupportingParts) == 'Instance' and SupportingParts:IsA('BasePart')
local PartsResult = SinglePart and {SupportingParts} or SupportingParts
-- Check {PartsResult IsA Table} --
print(SinglePart)
print(PartsResult)
if not SinglePart and (typeof(PartsResult) ~= 'table' or #PartsResult == 0) then
warn('Invalid Parts Entry For Connection ' .. ConnectionName)
return
end
----
-- Understand {Connection Situation} --
self[ConnectionName] = self[ConnectionName] or {}
for _,BasePart in ipairs(PartsResult) do
-- Check {BasePart Properties} --
if BasePart and BasePart:IsA('BasePart') then
local Signal = BasePart[SignalType]
-- Check {Signal} --
if Signal and typeof(Signal.Connect) == 'function' then
if self[ConnectionName][BasePart] then
-- Disconnect {Connection} --
self[ConnectionName][BasePart]:Disconnect()
end
----
-- Connect {Connection} --
self[ConnectionName][BasePart] = Signal:Connect(CallBack)
else
-- Output {Invalid Connection SignalType} --
warn('Invalid SignalType Connection ' .. ConnectionName)
end
else
-- Output {Invalid Connection SignalType} --
warn('Invalid BasePart Entry Connection ' .. ConnectionName)
end
end
end
----
So if you are defining BoundParts as a table with all 3 values like so,
local BoundParts = ReceivedAsset:GetChildren()
then iterating through BoundParts (which is a table with all three Turf, HomeEndzone, and AwayEndzone like this,
for _,BoundPart in ipairs(BoundParts) do
if BoundPart.Name == 'HomeEndzone' then
print('Touched HomeEndzone')
elseif BoundPart.Name == 'AwayEndzone' then
print('Touched AwayEndzone')
elseif BoundPart.Name == 'Turf' then
print('Touched Turf')
end
end
It will print each one once because the table, BoundParts has each instance in it once. What is it that you are intending to do?
In the snippits you sent there are no checks for collisions or .Touched events. You just pass through the “Turf” model which has all 3 parts you are checking for within it, therefore firing all 3 prints.