Tick() taking processing time

function Damage(humanoid,damage,prot)
	if prot then
		if prot == 0.1 then
			humanoid.Parent.Shield.Health.Value -= damage/1.3
		else
			humanoid.Health -= (damage*prot)
		end
	else
		humanoid.Health -= damage
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		task.wait(3)
		local startTime
		while task.wait(0.1) do
			local humPart = char:FindFirstChild("HumanoidRootPart")
			local humanoid = char:FindFirstChild("Humanoid")
			if humPart and humanoid then
				local part = workspace:FindPartOnRay(Ray.new(humPart.Position,humPart.Position + Vector3.new(0,-4,0)),char)
				if not part then
					startTime = tick()
				else
					if startTime then
						local currentTime = tick()
						if currentTime - startTime >= 0.5 then
							startTime = nil
							Damage(humanoid,25,char:FindFirstChild("Protection"))
						end
					end
				end
			end
		end
	end)
end)

Nothing much to say here, but the script works fine with damaging me, but it takes about a half second to damage me after I land.

2 Likes

Are you sure it’s tick and not the task.wait(0.1)? Have you tried task.wait() without the 0.1?

image

Here’s a simplified version

local rs = game:GetService("RunService")
function Damage(humanoid,damage,prot)
	if prot then
		if prot == 0.1 then
			humanoid.Parent.Shield.Health.Value -= damage/1.3
		else
			humanoid.Health -= damage*prot
		end
	else
		humanoid.Health -= damage
	end
end
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		task.wait(3)
		local damageTime = 0
		while rs.Heartbeat:Wait() do
			local humPart = char:FindFirstChild("HumanoidRootPart")
			local humanoid = char:FindFirstChild("Humanoid")
			if humPart and humanoid then
				local part = workspace:FindPartOnRay(Ray.new(humPart.Position,humPart.Position - Vector3.new(0,4,0)),char)
				if part then
					if tick()-damageTime > 0.5 then
						damageTime = tick()
						Damage(humanoid,25,char:FindFirstChild("Protection"))
					end
				end
			end
		end
	end)
end)