Best way to write this code?

What is the best way to write this code?

zone.playerEntered:Connect(function(player)
	game.ReplicatedStorage.OnEnterDevilsPalm:FireAllClients(true)
	hasLeft = false
	while not debounceForDamage and not hasLeft do
		debounceForDamage = true
		player.Character.Humanoid.Health -= (1/player.Character.Humanoid.MaxHealth)*100
		wait(2)
		debounceForDamage = false
	end
	while not debounceForCorpsePart and not hasLeft do
		debounceForCorpsePart = true
		print("Hello")
		wait(10)
		debounceForCorpsePart = false
	end
end)

What exactly is this script trying to do? Could you provide some additional context such as variable declarations?

When the player is inside the area the player gets damaged, and the player has a chance to get an item
but I want different wait times when the player gets damage and when he gets a item.

I think its a JJBA game about Devil’s Palm which damages you per sec

1 Like
zone.playerEntered:Connect(function(player)
	hasLeft = false
	game.ReplicatedStorage.OnEnterDevilsPalm:FireAllClients(true)
	if not debounceForDamage then
		repeat
			debounceForDamage = true
			player.Character.Humanoid.Health -= (1/player.Character.Humanoid.MaxHealth)*100
			task.wait(2)
			debounceForDamage = false
		until hasLeft
	end
	if not debounceForCorpsePart then
		repeat
			debounceForCorpsePart = true
			task.wait(10)
			debounceForCorpsePart = false
		until hasLeft
	end
end)

Do you need to use FireAllClients()? Would FireClient() suffice? You already have the player object which is required for FireClient() calls.