-
What do you want to achieve?: Read a variable using a Bindable Event
-
What is the issue? The variable always returns nil, even though it is changed and the change is registered
-
What solutions have you tried so far? I googled it, didn’t find any answers
local PickUpBall = {}
PickUpBall.__index = PickUpBall
local CS = game:GetService("CollectionService")
local BallInHand = nil
function PickUpBall:InputEnded()
if BallInHand then return end
local Character = PickUpBall.Owner.Character
if not Character then return end
local Ball = PickUpBall.Shared.FindBall()
if not Ball then return end
Ball.CanCollide = false
Ball.CFrame = Character["Right Arm"].CFrame + Vector3.new(0,-1.5,0)
CS:RemoveTag(Ball, "Soccer")
local WeldConstraint = Instance.new("WeldConstraint", Ball)
WeldConstraint.Name = "HoldConstraint"
WeldConstraint.Part0 = Character["Right Arm"]
WeldConstraint.Part1 = Ball
PickUpBall.Events.PlayAnimation:Fire(11872244344, 0.5)
BallInHand = Ball
--a print(BallInHand) returns Ball
end
function PickUpBall:Cancel()
if not BallInHand then return end
CS:AddTag(BallInHand, "Soccer")
if BallInHand:FindFirstChild("HoldConstraint") then
BallInHand.HoldConstraint:Destroy()
end
BallInHand.CanCollide = true
BallInHand = nil
end
function PickUpBall:Start()
PickUpBall.Events.DropBall.Event:Connect(function()
PickUpBall:Cancel()
end)
PickUpBall.Events.GetBallInHand.Event:Connect(function()
return BallInHand -- Problematic line, it always returns nil
end)
end
return PickUpBall