Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this code dealing too much damage?

I made script that infects others when infected player touch them, but it deals too much damage than it should (i also noticed player that is infected also gets damaged too much)


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character) 
		Character:FindFirstChild("Humanoid").Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid")then
				if not (hit.Parent == game.Workspace.infected) and (Character.Parent == game.Workspace.infected) then
					local BodyColors = hit.Parent:FindFirstChild("Body Colors")
					local newInfected = hit.Parent
					newInfected.Parent = game.Workspace.infected
					wait(5)
					if not hit.Parent:FindFirstChild("Humanoid") then return end
					local health = hit.Parent:FindFirstChild("Humanoid").Health
					while health > 0 do
						health = health - 1
						hit.Parent:FindFirstChild("Humanoid").Health = health
						wait(5)
					end
				end
			end
		end)
	end)
end)

1 comment

0

Add a debounce

1 answer

 health = health - 1

This line of code makes the player lose their full health instantly, what you should try is adding a wait after the line of code I said before.

1 comment

0

It doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.