Hello Developers,
I am coding a football for a league and I am confused on why this code isn’t working. The ball is going to the characters Rootpart. But the Bool Value that suppose to check when its attached to the rootpart isn’t checking please help.
The Code:
-- Variables
local Ball = script.Parent.Parent
local BallValue = script.Parent.Parent.Values:GetChildren()
local Attachment = script.Parent.Parent:WaitForChild( 'Attach' )
-- Main Code
Ball.Touched:Connect(function(PickedUp)
if not PickedUp.Parent:FindFirstChild( 'Humanoid' ) then return end
if PickedUp.Parent:FindFirstChild( Ball ) then return end
-- Attach
Attachment.Part0 = PickedUp.Parent:FindFirstChild( 'HumanoidRootPart' )
-- Check Ball
BallValue.HasBall.Changed:Connect(function()
if Attachment.Part0 == PickedUp.Parent:FindFirstChild( 'HumanoidRootPart' ) and BallValue.HasBall.Value == false then
BallValue.HasBall.Value = true
else
BallValue.HasBall.Value = false
end
end)
end)
I think the problem is that you added GetChildren() in the BallValue variable. Remove GetChildren() from the variable, see if that’ll work.
It should look like this:
local BallValue = script.Parent.Parent.Values -- removed GetChildren()
You can also use WaitForChild or FindFirstChild method when mentioning the Boolean Value, though this may not be needed.
BallValue.HasBall.Changed:Connect(function()
if Attachment.Part0 == PickedUp.Parent:FindFirstChild("HumanoidRootPart") and BallValue.HasBall.Value == false then
BallValue:FindFirstChild("HasBall").Value = true
else
BallValue:FindFirstChild("HasBall").Value = false
end
end)
Okay so the script is located inside of a folder called Code and inside the folder the scripts name is PickupServer cause its a serverscript. The bool value is in its sperate folder called Values. That were I store all the values so its more organized when I want to add a new value or a script