So my problem is that when the tool is activated, it is suppose to do damage to surrounding players. It works fine until the NPC respawns or another one is defeated. The script is not picking up the newly added children, just ignoring them all together.

local Server = game:GetService("Players")

local Workspace = game:GetService("Workspace")

local Tool = script.Parent



local Punch = Tool:WaitForChild("Punch")

local GuardUp = Tool:WaitForChild("GuardUp")

local Animation = script:WaitForChild("Animation")



local Default = {

[1] = script:WaitForChild("Attack1"),

[2] = script:WaitForChild("Attack2")

}



local AttackSettings = {

[1] = "RightHand",

[2] = "LeftHand",

}



GuardUp.OnServerEvent:Connect(function(Player, Equip)

local Character = Player.Character

local Humanoid = Character:FindFirstChild("Humanoid")

local Track = Humanoid:LoadAnimation(Animation)

if Equip == true then



	if not Humanoid then return end

	Track:Play()

else

	Track:Stop()

	end

end)







Punch.OnServerEvent:Connect(function(Player, Combo)

	local Character = Player.Character

	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

	local Player_Data = Player:FindFirstChild("Player_Data")

	local Melee = Player_Data:FindFirstChild("Melee")

	local Animation = Default[Combo]

	if Humanoid.Health <= 0 then return end

	local Track = Humanoid:LoadAnimation(Animation)

	Track:Play()

	local Min = Character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * 1

	local Max = Character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * 5

	for looping, child in pairs(Workspace:GetChildren()) do

		if child:IsA("Model") then

			if child == Character then return end

			local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

			local Part = child:FindFirstChild("HumanoidRootPart")

			local EnemyHumanoid = child:FindFirstChildWhichIsA("Humanoid")

			if EnemyHumanoid then

				if HumanoidRootPart then

					if Part then

						local Distance = (Character:FindFirstChild(AttackSettings[Combo]).Position - Part.Position).Magnitude

						if Distance > 1 and Distance <= 3 then

	  

							EnemyHumanoid:TakeDamage((1.1 * Melee.Value) + 5)

							if Player_Data then

								local MeleeExp = Player_Data:FindFirstChild("MeleeExp")

								if MeleeExp then

									MeleeExp.Value = (MeleeExp.Value + (math.random(5, 10)))

								end

							end

						end

					end

				end

			end

		end

	end

end)

Is there any sort of reason for this? The :GetChildren table should update every time the remote event was fired, so how come it isn't working here?

In this gif, you can see that the tool works until the NPC dies. GIF1

and here, you can see that it only starts working again after a different NPC has died GIF2

3 comments

0

The workspace is easily accessible, it follows the same principles as game. Simply write 'workspace' and you're Good.

0

I also don't see any Tool.Activated Signal or the Remote "Punch" or "GuardUp" being Fired in the first place.

0

oh, that's because I am also using a Local Script and Remote Events. workspace won't work because I am already using it. 'Workspace' has been defined at the top.