Why is this script not working?

How come this is not working? only the first print statement plays then nothing else no errors or all the print statements in for loop.

local part = script.Parent
local characters = {}

while true do 
	task.wait(5)
	print("Going through loop")
	for i, character in pairs(characters) do
		print(character)
		local distance = (part - character:WaitForChild("HumanoidRootPart")).Magnitude
		print(distance)
			if distance <= 10 then 
			character.Humanoid.Health += 1
			print("giving life to"..character.Name)
			else 
				character.Humanoid.Health -= 5
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		table.insert(characters, char)
	end)
	player.CharacterRemoving:Connect(function(char)
		table.remove(characters, char)
	end)
end)
1 Like
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		table.insert(characters, char)
	end)
	player.CharacterRemoving:Connect(function(char)
		table.remove(characters, table.find(char))
	end)
end)

also put the while loop after the events smh…

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