Humanoid.Died only printing but not doing other things

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)
1 Like

Try printing grabbed.Value and HasBall.Value and check if it really does not change the value

grabbed.Value = false
print("Grabbed Value:", grabbed.Value)
Ball.HasBall.Value = nil
print("HasBall Value:", Ball.HasBall.Value)

A little silly that you create variables then forget to use them

local Ball = script.Parent
local Hits = {}
local grabbed = Ball.Grabbed

script.Parent.Grabbed.Value = false
script.Parent.HasBall.Value = nil

you should change it to this

local Ball = script.Parent
local Hits = {}
local grabbed = Ball.Grabbed
local hasball = Ball.HasBall

grabbed.Value = false
hasball.Value = nil

I was trying to check if variables effect it so I just left it like that.

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.

The Died event is connected to the Character, which gets replaced with a new Character on respawn so you will have factor this into your thinking.

Add this to a CharacterAdded event instead

player.CharacterAdded:Connect(function(char)
  local humanoid = char:WaitForChild("Humanoid")
  humanoid.Died:Connect(function()
    Died()
  end)
end)

Ok I will try it out this with character added.

I figured out that debris works it is the value.