I have made a basketball game but when a player dies you can’t pick up the basketball since it is implemented with values. I tried fixing it but it would only print. I do not see a problem so any help would be great.
local Ball = script.Parent
local Hits = {}
local grabbed = Ball.Grabbed
local debris = game:GetService("Debris")
local function Died()
print("Died")
script.Parent.Grabbed.Value = false
script.Parent.HasBall.Value = nil
end
Ball.Touched:Connect(function(hit)
if hit.Parent:WaitForChild("Humanoid", 1)and grabbed.Value == false then
if Hits[hit.Parent.Name] then
return
end
Hits[hit.Parent.Name] = true
if hit.Parent:WaitForChild("HumanoidRootPart", 1) and grabbed.Value == false then
grabbed.Value = true
local LeftHand = hit.Parent:FindFirstChild("LeftHand")
local Humaniod = hit.Parent:WaitForChild("Humanoid", 1)
if LeftHand and Humaniod then
Humaniod.Died:Connect(Died)
Ball.HasBall.Value = hit.Parent
local Attach = LeftHand:WaitForChild("LeftGripAttachment")
local LeftGrip = Instance.new("Weld")
LeftGrip.Name = ("Dual")
LeftGrip.Part0 = LeftHand
LeftGrip.Part1 = Ball
LeftGrip.C0 = CFrame.new(0, -0.5, 0, 1, 0, -0, 0, 0, 1, 0, -1, -0)
LeftGrip.C1 = (Attach.CFrame * CFrame.Angles(0, 0, -math.pi))
LeftGrip.Parent = Ball
game.ServerStorage.WeldValue.Value = LeftGrip
end
end
delay(0.2, function()
Hits[hit.Parent.Name] = nil
end)
end
end)
You need to use the variables because you can’t look for ancestors/children and properties in the same line.
script.Parent.Grabbed.Value doesn’t do anything I believe because it is searching for Value as a child of Grabbed instead of as a property of grabbed.
That’s why you declare the variable grabbed so with grabbed.Value the script knows it’s not searching for children of grabbed but the properties of it.