No error but coding doesn't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Get my Client onChildRemove working.

  2. What is the issue?
    Prints aren’t working, nor is my functions inside of it working properly.

  3. What solutions have you tried so far?
    Have looked through the forum many times and seems that others are also having problems with ChildRemoved.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local function onChildRemoved(instance)
	print("Child Removed Function Triggered")
	if instance.Name == "Football" then
		print("Child Removed", instance.Name)
		BallGui:Destroy()
		AnimationsModule:StopAllAnimations()
	end
end

Character.ChildRemoved:Connect(onChildRemoved)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Hi. I don’t see any problem with the code by itself but:

  • Make sure that this is a LocalScript / Script with the RunContext set to Client, parented to one of the proper locations so that you know the code is actually running. Verify this with a print outside of the function

  • Show us your Explorer and Output windows to confirm you did that

  • Have you made sure that this Instance "Football" is in the character in the first place? Is it named exactly "Football" (case sensitive)?

1 Like

I’m going to do that right now.

Where is the code responsible for removing the football from the character ?

Once the football is removed from the character it stops all animations and destroys the ballgui.

What @magical_artistery said, yeah, this will help us answer the question to your problem. Another tip of mine would be to do more debugging. Another potential issue is: If the code responsible for removing the football is on the server, the client won’t see what happened. The football has to be removed from the client.

The code is on the client! It’s been acting up only in this new game I made. In my other game I made a few months ago it worked perfectly fine.

You should maybe try looking inside the character in Explorer to see if the football was even deleted. If it isn’t, then that might be the problem. To help further though, it’ll be best to find out the code for deleting the football. You don’t have to send us the whole thing, just the main part which removes the football from the character.

local function Throw(Origin, Target, Power, Throwtype, Tackled, Player)
	local NewPower = Power
	Player.Character.ChildRemoved:Connect(FootballModule.OnChildRemoved)
	if Football:IsA("MeshPart") then
		if Throwtype ~= 4 then
			if Player.Character.Hitbox:GetAttribute("Position") == "QB" then
				if Player.Character.Hitbox:GetAttribute("Archetype") == "Gunslinger" then
					if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
						NewPower = NewPower + 10
					else
						NewPower = NewPower + 5
					end
				elseif Player.Character.Hitbox:GetAttribute("Archetype") == "Magician" then
					if Player.Character.Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
						NewPower = NewPower - 7
					end
				end
			end
			if Throwtype == 1 then
				if Player.Character.Hitbox:GetAttribute("Position") == "QB" then
					if Player.Character.Hitbox:GetAttribute("Archetype") == "Conductor" then
						if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
							NewPower = NewPower * .85
						else
							NewPower = NewPower * .79
						end
					elseif Player.Character.Hitbox:GetAttribute("Archetype") == "Magician" then
						if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
							NewPower = NewPower * .80
						else
							NewPower = NewPower * .77
						end
					end
				else
					if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
						NewPower = NewPower * .75
					else
						NewPower = NewPower * .70
					end
				end
			end
			if Throwtype == 2 then
				if Player.Character.Hitbox:GetAttribute("Position") == "QB" then
					if Player.Character.Hitbox:GetAttribute("Archetype") == "Gunslinger" then
						if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
							NewPower = NewPower * .95
						else
							NewPower = NewPower * .75
						end
					end
				end
			elseif Throwtype == 3 then
				Football.Kick:Play()
				if Kicked then
					NewPower = KickPower
				end
			elseif Throwtype == 5 then
				NewPower = Power * .6
			end
		end
		if Tackled then
			NewPower = NewPower * .6
		end
		Ready = false
		if Throwtype ~= 4 then
			Football.Client.BallGui.PowerFrame.Bar.PowerLabel.Text = tostring(math.min(Power, 100))
		else
			Football.Client.BallGui.PowerFrame.Bar.PowerLabel.Text = tostring(math.min(LastPower, 100))
		end
		Football.CanCollide = true
		if Throwtype == 3 then
			Football:SetAttribute("Kicked", true)
		end
		spawn(function()
			Football.CanTouch = false
			wait(.3)
			Football.CanTouch = true
		end)
		Football.Parent = game.Workspace
		Football:SetAttribute("Thrown", true)
		Football:SetAttribute("Mode", "Running")
		Football:SetAttribute("Catchable", true)
		Football:SetAttribute("Kickable", false)
		Football:SetAttribute("Equipped", false)
		Football:SetAttribute("Throwing", false)
		Football:SetAttribute("Snapping", false)
		Football:SetAttribute("Kicked", false)
		Kicked = false
		if Player ~= nil and Player:FindFirstChild("Head") ~= nil then
			if Throwtype == 1 or Throwtype == 2 then
				Origin = (Player.Head.CFrame * CFrame.new(1.5, 0, 0)).p
			elseif Throwtype == 5  then
				Origin = (Player.Head.CFrame * CFrame.new(0, -2, 0)).p
			else
				Origin = Player.Head.CFrame
			end
		end
		local Aim = (Target - Origin).unit
		local SpawnPos = Origin + (Aim * 5)
		local TargetPos = SpawnPos + (Aim * math.max(1, NewPower))
		Football.Position = SpawnPos
		if Tackled == false then
			Football.Velocity = Aim * NewPower
		else
			Football.Velocity = (Aim * NewPower) + Vector3.new(0, math.random(5,10), 0)
		end
		Football.CFrame = CFrame.new(SpawnPos, TargetPos) * CFrame.Angles(math.pi/2, 2, 0)
		local BodyVelocity = Instance.new("BodyVelocity", Football)
		BodyVelocity.MaxForce = Vector3.new(1e3, 1e3, 1e3)
		BodyVelocity.P = NewPower * 100
		if Tackled == false then
			BodyVelocity.Velocity = (TargetPos - Football.CFrame.p).unit * (NewPower - 5)
		else
			BodyVelocity.Velocity = ((TargetPos - Football.CFrame.p).unit * NewPower) + Vector3.new(0, math.random(0,15), 0)
		end
		-- GRAVITY --
		Football.FlyingSound:Stop()
		Football.FlyingSound:Play()
		FreeFalling = true
		Ready = true
		local i = 0
		local Gravity0 = Football:GetAttribute("Gravity")
		local Gravity1
		local AirRessitance = Football:GetAttribute("AirResistance")
		while FreeFalling do
			Gravity1 = Gravity0 + (AirRessitance * (1 - math.abs(Football.CFrame.UpVector.Y)))
			if Throwtype ~= 1 or Throwtype ~= 2 or Throwtype ~= 3 or Throwtype ~= 4 or Throwtype ~= 5 then
				BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(0, Gravity1 * RunService.Heartbeat:Wait(), 0)
			else
				BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(game.Workspace.GlobalWind.X * .000115, -38 * RunService.Heartbeat:Wait(), 0)
			end
			local P = Football.CFrame.p
			if Tackled == false then
				if Throwtype == 1 or Throwtype == 5 then
					i = i + 0.18
					if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
						Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(math.pi/2, math.pi * i, math.pi/2)
					else
						Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(.75 * math.pi/2, math.pi * i, .75 * math.pi/2)
					end
				elseif Throwtype == 2 then
					i = i + 0.16
					if Player.Character.Hitbox:GetAttribute("Position") == "QB" then
						if Player.Character.Hitbox:GetAttribute("Archetype") == "Gunslinger" then
							if Player.Character.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
								Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(math.pi/2, math.pi * i, math.pi/2)
							else
								Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(.75 * math.pi/2, math.pi * i, .75 * math.pi/2)
							end
						end
					end
				elseif Throwtype == 3 then
					i = i + 0.17
					Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(math.pi * i, .75 * math.pi/2, .75 * math.pi/2)
				elseif Throwtype == 4 then
					i = i + 0.08
					Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(.75 * math.pi/2, math.pi * i, .75 * math.pi/2)
				end
			else
				i = i + 0.1
				if Throwtype == 1 or Throwtype == 2 or Throwtype == 5 then
					Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(.75 * math.pi/2, math.pi * i, .75 * math.pi/2)
				else
					Football.CFrame = CFrame.new(P, P + BodyVelocity.Velocity + Buffer) * CFrame.Angles(math.pi/2, math.pi * i, math.pi/2)
				end
			end
		end
	end
end

I decided to use Player.Character.DescendantRemoving instead and it’s working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.