Hello Devs.
Im currently working on a catching system for a commission and I’ve ran into a serious problem. When I use my Find Football Function Module.FindFootball
to find the football in the workspace. The Module.CatchMechanic
returns me a error that it can’t find the Football. I ran the Module.FindFootball
In other instances to find the football so you can go into ball camera and it works just find. Why does it do this?
Image:
Code:
function Module:FindFootball()
if workspace:FindFirstChild('Football') then
-- Finish Code --
return workspace:FindFirstChild('Football')
end
for _,Plr in PlrService:GetPlayers() do
-- Check --
if not Plr.Character then continue end
local Football = Plr.Character:FindFirstChild('Football')
-- Check --
if Football and Football:IsA('MeshPart') then
return Football
end
end
end
function Module:CatchMechanic()
-- Boolean {Check} --
if CanCatch == true then
CanCatch = false
-- Constants {Football} --
local Football = Module.FindFootball()
if not Football then
-- Middle Catching Only --
RemoteEvent:FireServer({'NewAction','CatchingTrue'})
AvatarAnimations.FootballAnims.CatchAnims.MiddleAnimation:Play()
-- Wait Until {Stopped} --
AvatarAnimations.FootballAnims.CatchAnims.MiddleAnimation.Stopped:Wait()
RemoteEvent:FireServer({'NewAction','CatchingFalse'})
else
-- Check {Football.Parent}
if Football then
-- Update {Distances} --
MidDistance = Module.GetDistance(HumanoidRootPart,Football)
HighDistance = Module.GetDistance(Head,Football)
LowLDistance = Module.GetDistance(LeftLeg,Football)
LowRDistance = Module.GetDistance(RightLeg,Football)
LeftDistance = Module.GetDistance(LeftArm,Football)
RightDistance = Module.GetDistance(RightArm,Football)
-- Fire Event --
RemoteEvent:FireServer({'NewAction','CatchingTrue'})
-- Select Which Animation Will Be Playing --
local Distances = {MidDistance,HighDistance,LowLDistance,LowRDistance,LeftDistance,RightDistance}
local Closest = nil
-- For Statement --
for I = 2,#Distances do
if Distances[I] < Distances[I - 1] then
-- Set Closest Value --
Closest = Distances[I]
end
end
-- Now Play Animations {Check Closest} --
if Closest == MidDistance then
AvatarAnimations.FootballAnims.CatchAnims.MiddleAnimation:Play()
elseif Closest == HighDistance then
AvatarAnimations.FootballAnims.CatchAnims.HighAnimation:Play()
elseif Closest == LowLDistance then
AvatarAnimations.FootballAnims.CatchAnims.LowAnimation:Play()
elseif Closest == LowRDistance then
AvatarAnimations.FootballAnims.CatchAnims.LowAnimation:Play()
elseif Closest == LeftDistance then
AvatarAnimations.FootballAnims.CatchAnims.LeftAnimation:Play()
elseif Closest == RightDistance then
AvatarAnimations.FootballAnims.CatchAnims.RightAnimation:Play()
end
-- Wait Then Fire Event --
task.wait(0.75)
RemoteEvent:FireServer({'NewAction','CatchingFalse'})
end
end
task.wait(0.5)
CanCatch = true
end
end